读文件的时候要使用private ArrayList infomore = new ArrayList();
StreamReader srReadLine;
srReadLine = new StreamReader((Stream)File.OpenRead("x.txt"),Encoding.Default);也就是要改变读取文件时的编码格式srReadLine.BaseStream.Seek(0, SeekOrigin.Begin);
while (srReadLine.Peek() > -1)
{
a tmp;
tmp.x = ?
tmp.x = srReadLine.ReadLine();
infomore.add(tmp)
}
srReadLine.Close();还有:在C#中怎么一次读一个结构读取文件。
如一个结构体 struct a
{
public int x;
public char[10] s;
}
怎么样一次把文件中的数据读到这个结构体中?你的意思应该是怎么把文件按行读到一个结构体数组才对
StreamReader srReadLine;
srReadLine = new StreamReader((Stream)File.OpenRead("x.txt"),Encoding.Default);也就是要改变读取文件时的编码格式srReadLine.BaseStream.Seek(0, SeekOrigin.Begin);
while (srReadLine.Peek() > -1)
{
a tmp;
tmp.x = ?
tmp.x = srReadLine.ReadLine();
infomore.add(tmp)
}
srReadLine.Close();还有:在C#中怎么一次读一个结构读取文件。
如一个结构体 struct a
{
public int x;
public char[10] s;
}
怎么样一次把文件中的数据读到这个结构体中?你的意思应该是怎么把文件按行读到一个结构体数组才对
在VB 6.0里可以这样读一个文件:
Type MyStruct
a As String * 10
b As Long
c As Byte
End TypeDim tmpMyStruct As MyStruct
tmpMyStruct.a = "1234567890"
tmpMyStruct.b = 1234567
tmpMyStruct.c = 255Open "temp.dat" For Binary As #1
Put #1,,tmpMyStruct
Get #1,0,tmpMyStruct
Close #1在C #里怎么这样读文件?另外:
在C #里这样读一个由记事本保存的文本文件Stream temp_file;
byte[] buf_byte = new byte[2];
temp_file = new FileStream( "aa.txt" , FileMode.Open , FileAccess.Read );
temp_file.Read( buf_byte , 0 , 2 );
temp_file.Close();
temp_file = null;
textBox1.Text = ((char)((buf_byte[0] << 8) + buf_byte[1])).ToString();显示的不是我保存的那个字符。记事本保存的文本是用什么编码方式保存的?
(因为是在网吧里写的,所以有可能有部分语法错误,请见谅,但逻辑上应该没错)