C#读取txt数据存储到数组
2013-04-20 09:42
274 查看
public static void TextRead(out int[] data, string path)
{
data = new int[1];
try
{
FileStream fs = new FileStream(path, FileMode.Open);
using (StreamReader sr = new StreamReader(fs))
{
string line = sr.ReadToEnd().Replace("\r\n", " ");
string[] str2 = line.Split(' ');
int n = 0;
for (int i = 0; i < str2.Length; i++)
{
if (str2[i] != " ")
{
n++;
}
}
data = new int
;
n = 0;
for (int i = 0; i < str2.Length; i++)
{
if (str2[i] != " ")
{
data[n++] = Convert.ToInt32(str2[i]);
}
}
fs.Flush();
fs.Close();
}
}
catch (System.Exception e)
{
Console.Write("Error!{0}", e.Message);
Console.ReadKey();
}
}
{
data = new int[1];
try
{
FileStream fs = new FileStream(path, FileMode.Open);
using (StreamReader sr = new StreamReader(fs))
{
string line = sr.ReadToEnd().Replace("\r\n", " ");
string[] str2 = line.Split(' ');
int n = 0;
for (int i = 0; i < str2.Length; i++)
{
if (str2[i] != " ")
{
n++;
}
}
data = new int
;
n = 0;
for (int i = 0; i < str2.Length; i++)
{
if (str2[i] != " ")
{
data[n++] = Convert.ToInt32(str2[i]);
}
}
fs.Flush();
fs.Close();
}
}
catch (System.Exception e)
{
Console.Write("Error!{0}", e.Message);
Console.ReadKey();
}
}
相关文章推荐
- C#简单实现读取txt文本文件并分页存储到数组
- C#简单实现读取txt文本文件并分页存储到数组
- C# 读取txt文件存储在String数组中
- C# 自定义数据类型 数组应用 读取XML
- C#读取txt文档并且存储
- c#读取csv文件成DataTable,将DataTable数据存储为csv格式文件
- C#读取Access数据表中某一列内容,保存至数组
- C++读取以空格作为数据区分标记,以回车为行标记的txt文件到一个整数数组(字符串妙用)
- c#从txt读取数据填入datatable
- c#读取txt,xml,excel中的数据,绑定到lsitview ,dataview
- QT和VS读取.txt文件中的数据并保存为数组
- c#/.net用txt、in等作为数据存储的配置类
- 读取txt中的数据到数组中
- C#下 读取xml节点的数据总结 .txt
- 从txt文档中读取数据并做相应处理(c#)
- C#下 读取xml节点的数据总结 .txt
- C#窗体中,textbox中数据保存到txt文本中,从文本读取数据到textbox
- C#控制台控制台将一个文件夹中的所有txt文件中的数据读取出来
- C++读取txt中的数据到数组中
- C#下 读取xml节点的数据总结 .txt