国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 民和| 牟定县| 黔西县| 确山县| 都匀市| 黄浦区| 犍为县| 西昌市| 无锡市| 宜兴市| 左权县| 永春县| 贵德县| 夏河县| 兴隆县| 阿尔山市| 姜堰市| 醴陵市| 惠州市| 泸州市| 团风县| 方正县| 连平县| 怀安县| 黑河市| 宜章县| 神池县| 乐安县| 惠水县| 湘潭市| 博兴县| 冕宁县| 万载县| 建德市| 工布江达县| 北海市| 密云县| 泰和县| 陆川县| 日照市| 仪陇县|