国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

c# 讀取文件內(nèi)容存放到int數(shù)組 array.txt

2024-07-10 13:20:25
字體:
供稿:網(wǎng)友

復(fù)制代碼 代碼如下:


using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.IO;
using System.Text;
/// <summary>
/// Summary description for ReadFile
/// </summary>
public class ReadFile
{
public ReadFile()
{
//
// TODO: Add constructor logic here
//
}
public int[,] ReadFileToArray()
{
int[,] iret = null;
ArrayList alNumLine = getFileContent();
string[] strLineArr = null;
if (alNumLine.Count > 0)
{
strLineArr = Convert.ToString(alNumLine[0]).Trim(',').Split(',');
iret = new int[alNumLine.Count, strLineArr.Length];
for (int i = 0; i < alNumLine.Count; i++)
{
strLineArr = Convert.ToString(alNumLine[i]).Trim(',').Split(',');
for (int j = 0; j < strLineArr.Length; j++)
{
iret[i, j] = Convert.ToInt32(strLineArr[j]);
}
}
}
return iret;
}
public ArrayList getFileContent()
{
ArrayList alRet = new ArrayList();
string strFilePath = HttpContext.Current.Server.MapPath("~") + "/array.txt";
if (!File.Exists(strFilePath))
{
HttpContext.Current.Response.Write("文件[" + strFilePath + "]不存在。");
return alRet;
}
try
{
//讀出一行文本,并臨時(shí)存放在ArrayList中
StreamReader sr = new StreamReader(strFilePath, Encoding.GetEncoding("gb2312"));
string l;
while ((l = sr.ReadLine()) != null)
{
if (!string.IsNullOrEmpty(l.Trim()))
alRet.Add(l.Trim());
}
sr.Close();
}
catch (IOException ex)
{
HttpContext.Current.Response.Write("讀文件出錯(cuò)!請(qǐng)檢查文件是否正確。");
HttpContext.Current.Response.Write(ex.ToString());
}
return alRet;
}
}

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 探索| 英超| 孝感市| 雷波县| 乌兰察布市| 留坝县| 龙江县| 西乌| 弥勒县| 涟水县| 巴中市| 苗栗市| 普兰店市| 陆河县| 慈利县| 昌江| 武胜县| 加查县| 忻城县| 攀枝花市| 平潭县| 北安市| 英德市| 新和县| 阿拉尔市| 陆河县| 屯昌县| 彝良县| 德惠市| 开封市| 石城县| 乐陵市| 合江县| 盱眙县| 贵南县| 噶尔县| 阜城县| 获嘉县| 铁岭县| 获嘉县| 白山市|