新手求助 读取txt文件到数组中显示出来 报错

[复制链接]
查看11 | 回复1 | 2011-8-28 03:41:47 | 显示全部楼层 |阅读模式
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace Example{

class Program

{

private void ReadIPFromTxtFile()

{

string txtContext = string.Empty;

string fileName = "d:\\text.txt";

if (File.Exists(fileName))

{

StreamReader sr = new StreamReader(fileName);

txtContext = sr.ReadLine(); //读取文件,假设文字在第一行

sr.Close();

}

if (string.IsNullOrEmpty(txtContext) == false)

{

string[] strArr = txtContext.Split(new char[] { ' ' });

if (strArr.Length > 0)

{

byte[] indata = new byte[strArr.Length];

for (int i = 0; i < strArr.Length; i++)

{

indata = byte.Parse(strArr); //把字符转换成byte数组里的元素


}



}

}

}
static void Main(string[] args)

{

for (int i = 0; i < indata.Length; i++)

{

Console.WriteLine("pulao" + indata);

Console.ReadKey();

}



}
}


}
报错:错误        1        当前上下文中不存在名称“indata”         求高手指点

回复

使用道具 举报

千问 | 2011-8-28 03:41:47 | 显示全部楼层
比如有一个数组a()内有5个数1 2 3 4 5,我想将它写入到0.txt文件中...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行