日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#讀取文件內(nèi)容另存的實(shí)現(xiàn)

C#讀取文件內(nèi)容另存的實(shí)現(xiàn)的如何呢?讓我們看看代碼的實(shí)現(xiàn):

 
 
 
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Collections;
  11. using System.IO;
  12. using System.Text;
  13. /// 
  14. ///C#讀取文件內(nèi)容另存
  15. /// Summary description for ReadFile
  16. ///
  17.  
  18. public class ReadFile
  19. {
  20.  public ReadFile()
  21.  {
  22.    //  C#讀取文件內(nèi)容
  23.    // TODO: Add constructor logic here
  24.  //
  25.     }
  26.     public int[,] ReadFileToArray()
  27.     {
  28. int[,] iret = null;  //C#讀取文件內(nèi)容另存
  29.  ArrayList alNumLine = getFileContent();
  30.    string[] strLineArr = null;
  31.  if (alNumLine.Count > 0)
  32.         {
  33.     strLineArr = Convert.ToString(alNumLine[0]).Trim(',').Split(',');
  34.   iret = new int[alNumLine.Count, strLineArr.Length];
  35.     for (int i = 0; i < alNumLine.Count; i++)
  36.             {
  37.  strLineArr = Convert.ToString(alNumLine[i]).Trim(',').Split(',');
  38.  for (int j = 0; j < strLineArr.Length; j++)
  39.  {
  40.     iret[i, j] = Convert.ToInt32(strLineArr[j]);
  41.    }
  42.             }
  43.         }
  44.         return iret;
  45.     }
  46.  //C#讀取文件內(nèi)容另存
  47.     public ArrayList getFileContent()
  48.     {
  49.  ArrayList alRet = new ArrayList();
  50.  string strFilePath = HttpContext.Current.Server.MapPath("~")
  51. + "/array.txt";
  52.  if (!File.Exists(strFilePath))
  53.         {
  54.  HttpContext.Current.Response.Write("文件[" + strFilePath + "]不存在。");
  55.             return alRet;
  56.         }
  57.  //C#讀取文件內(nèi)容另存
  58.         try
  59.         {
  60.  //讀出一行文本,并臨時(shí)存放在ArrayList中
  61.     StreamReader sr = new StreamReader(strFilePath,
  62. Encoding.GetEncoding("gb2312"));
  63.   string l;
  64.    while ((l = sr.ReadLine()) != null)
  65.             {
  66.    if (!string.IsNullOrEmpty(l.Trim()))
  67.         alRet.Add(l.Trim());
  68.             }
  69.             sr.Close();
  70.         }
  71.         catch (IOException ex)
  72.         {
  73.   HttpContext.Current.Response.Write("讀文件出錯(cuò)!請(qǐng)檢查文件是否正確。");
  74.   HttpContext.Current.Response.Write(ex.ToString());
  75.         }
  76.         return alRet;
  77.  //C#讀取文件內(nèi)容另存
  78.     }
  79. }

C#讀取文件內(nèi)容另存的實(shí)現(xiàn)就向你介紹到這里,希望通過這樣的介紹使你能夠明白C#讀取文件內(nèi)容另存相關(guān)內(nèi)容,希望對(duì)你有所幫助。


分享標(biāo)題:C#讀取文件內(nèi)容另存的實(shí)現(xiàn)
分享鏈接:http://www.5511xx.com/article/ccojiic.html