自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C#讀取文件內(nèi)容另存的實(shí)現(xiàn)

開發(fā) 后端
C#讀取文件內(nèi)容另存的實(shí)現(xiàn)是如何的呢?那么本文就向你介紹C#讀取文件內(nèi)容另存放到int數(shù)組 array.txt的實(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. /// 
  15. ///C#讀取文件內(nèi)容另存 
  16. /// Summary description for ReadFile  
  17. /// 
  18.  
  19. public class ReadFile  
  20. {  
  21.  public ReadFile()  
  22.  {  
  23.    //  C#讀取文件內(nèi)容
  24.    // TODO: Add constructor logic here  
  25.  //  
  26.     }  
  27.  
  28.  
  29.     public int[,] ReadFileToArray()  
  30.     {  
  31.  
  32. int[,] iret = null;  //C#讀取文件內(nèi)容另存
  33.  
  34.  ArrayList alNumLine = getFileContent();  
  35.    string[] strLineArr = null;  
  36.  if (alNumLine.Count > 0)  
  37.         {  
  38.     strLineArr = Convert.ToString(alNumLine[0]).Trim(',').Split(',');  
  39.   iret = new int[alNumLine.Count, strLineArr.Length];  
  40.     for (int i = 0; i < alNumLine.Count; i++)  
  41.             {  
  42.  strLineArr = Convert.ToString(alNumLine[i]).Trim(',').Split(',');  
  43.  for (int j = 0; j < strLineArr.Length; j++)  
  44.  {  
  45.     iret[i, j] = Convert.ToInt32(strLineArr[j]);  
  46.    }  
  47.             }  
  48.         }  
  49.  
  50.         return iret;  
  51.  
  52.     }  
  53.  //C#讀取文件內(nèi)容另存
  54.  
  55.     public ArrayList getFileContent()  
  56.     {  
  57.  
  58.  ArrayList alRet = new ArrayList();  
  59.  
  60.  string strFilePath = HttpContext.Current.Server.MapPath("~"
  61. "/array.txt";  
  62.  
  63.  if (!File.Exists(strFilePath))  
  64.         {  
  65.  HttpContext.Current.Response.Write("文件[" + strFilePath + "]不存在。");  
  66.             return alRet;  
  67.         }  
  68.  //C#讀取文件內(nèi)容另存
  69.         try 
  70.         {  
  71.  //讀出一行文本,并臨時(shí)存放在ArrayList中  
  72.     StreamReader sr = new StreamReader(strFilePath, 
  73. Encoding.GetEncoding("gb2312"));  
  74.   string l;  
  75.    while ((l = sr.ReadLine()) != null)  
  76.             {  
  77.    if (!string.IsNullOrEmpty(l.Trim()))  
  78.         alRet.Add(l.Trim());  
  79.             }  
  80.             sr.Close();  
  81.         }  
  82.         catch (IOException ex)  
  83.         {  
  84.   HttpContext.Current.Response.Write("讀文件出錯!請檢查文件是否正確。");  
  85.   HttpContext.Current.Response.Write(ex.ToString());  
  86.         }  
  87.  
  88.         return alRet;  
  89.  //C#讀取文件內(nèi)容另存
  90.  
  91.     }  

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

【編輯推薦】

  1. C#讀取XML文檔的實(shí)現(xiàn)淺析
  2. C#讀取XML節(jié)點(diǎn)內(nèi)容方法實(shí)例簡析
  3. C#讀取XML文檔使用XMLTextReader類淺析
  4. C#讀取文件夾中的文件操作淺析
  5. C#讀取文件夾下面的全部文件的實(shí)現(xiàn)
責(zé)任編輯:仲衡 來源: 百度空間
相關(guān)推薦

2009-08-12 18:29:06

C#讀取TXT文件

2009-09-01 11:21:02

C#讀取word內(nèi)容

2009-09-02 19:08:03

C#實(shí)現(xiàn)讀取文本文件

2009-08-12 17:12:51

C#讀取文件夾

2009-08-13 10:15:50

C#讀取Excel

2009-08-21 16:13:27

C#讀取資源文件

2009-08-13 09:32:00

C#讀取TXT文件

2009-09-09 18:00:55

C# XML編程

2009-08-12 16:26:30

C#讀取XML文檔

2009-09-10 09:42:53

C# TextBox

2009-08-13 09:58:55

C#讀取配置文件

2009-08-13 09:16:57

C#讀取配置文件

2009-08-12 17:27:11

C#讀取文件

2009-09-01 11:25:08

C#讀取Word文件

2009-08-24 17:58:19

C#讀取XML文件

2009-08-12 16:57:28

C#讀取文件夾

2009-08-18 13:35:06

C#枚舉文件

2009-08-12 16:38:35

C#讀取XML節(jié)點(diǎn)

2009-08-21 17:48:13

C#讀取文件信息

2009-08-17 09:27:12

c# Windows
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號