StreamReader SR; string S; SR = new StreamReader("你的文件",Encoding.GetEncoding("GB2312")); S = SR.ReadLine(); while (S != null) { //Console.WriteLine(S); T_FirstText.AppendText(S + Environment.NewLine); S = SR.ReadLine(); } SR.Close();
ASP.NET(c#,Ajax)技术讨论群30417196(限已工作人士)
maoliner(控制面板)和wooting(不醉)的思路还真是有趣,不同的直觉,呵呵
if (!File.Exists(G_FtpLineCurFName)) { //current ftp line文件不存在; //Console.WriteLine("{0} 不存在!", G_FtpLineCurFName.ToString()); return; } // 文件存在,打开文件读取数据; StreamReader sr = File.OpenText(G_FtpLineCurFName); string delimStr = ",,"; string input; char[] delimiter = delimStr.ToCharArray(); // char [] delimiter = {","}; // string [] split= new string [6]{" "," "," "," "," "," "} ; string[] split = new string[6] { " ", " ", " ", " ", " ", " " };//列在后期调用时候自动分配,此处分配无效; while ((input = sr.ReadLine()) != null) { if ("" == input.Trim()) { continue; } for (int x = 1; x < 7; x++) { split = input.Split(delimiter, x); // // Console.WriteLine("\ncount = {0,2} ..............", x); } ListViewItem lvItem = new ListViewItem(split); // lvItem.Tag = split; if (lvTp4FLMonitor.InvokeRequired) { this.Invoke(new AddCallbackADD(LVIAdd), new Object[] { lvTp4FLMonitor, lvItem }); } else { this.lvTp4FLMonitor.Items.Add(lvItem); } } //Console.WriteLine("The end of the stream has been reached."); sr.Close();
请使用StreamReader、StreamWriter类...
string S;
SR = new StreamReader("你的文件",Encoding.GetEncoding("GB2312"));
S = SR.ReadLine();
while (S != null)
{
//Console.WriteLine(S);
T_FirstText.AppendText(S + Environment.NewLine);
S = SR.ReadLine();
}
SR.Close();
{
//current ftp line文件不存在;
//Console.WriteLine("{0} 不存在!", G_FtpLineCurFName.ToString()); return;
}
// 文件存在,打开文件读取数据; StreamReader sr = File.OpenText(G_FtpLineCurFName); string delimStr = ",,";
string input;
char[] delimiter = delimStr.ToCharArray();
// char [] delimiter = {","}; // string [] split= new string [6]{" "," "," "," "," "," "} ;
string[] split = new string[6] { " ", " ", " ", " ", " ", " " };//列在后期调用时候自动分配,此处分配无效; while ((input = sr.ReadLine()) != null)
{ if ("" == input.Trim())
{
continue;
} for (int x = 1; x < 7; x++)
{
split = input.Split(delimiter, x);
//
// Console.WriteLine("\ncount = {0,2} ..............", x); } ListViewItem lvItem = new ListViewItem(split);
// lvItem.Tag = split; if (lvTp4FLMonitor.InvokeRequired)
{
this.Invoke(new AddCallbackADD(LVIAdd), new Object[] { lvTp4FLMonitor, lvItem });
}
else
{
this.lvTp4FLMonitor.Items.Add(lvItem);
} } //Console.WriteLine("The end of the stream has been reached.");
sr.Close();