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

首頁 > 學院 > 開發設計 > 正文

c#讀取文件內容存放到int數組 array.txt

2019-11-17 04:17:05
字體:
來源:轉載
供稿:網友

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
        {
            //讀出一行文本,并臨時存放在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("讀文件出錯!請檢查文件是否正確。");
            HttpContext.Current.Response.Write(ex.ToString());
        }

        return alRet;


    }
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 马关县| 南涧| 监利县| 桂林市| 德惠市| 扎赉特旗| 清河县| 安龙县| 晋中市| 庆安县| 普兰县| 隆子县| 永顺县| 岳西县| 浦东新区| 横山县| 大余县| 西青区| 呈贡县| 莲花县| 柳州市| 武隆县| 高碑店市| 灵川县| 武威市| 凯里市| 万宁市| 南川市| 黔江区| 高青县| 山西省| 晋宁县| 乐安县| 白沙| 名山县| 永嘉县| 罗田县| 赫章县| 云南省| 古丈县| 客服|