Public static ListGetTextList (string FileName)
{
ListList=null;
Try
{
List=new List(a);
FileStream fs=new FileStream (FileName, FileMode. Open);
StreamReader sr=new StreamReader (fs, Encoding. The Default).
String STR=sr. ReadLine ();
While (STR!=string. The Empty)
{
If (STR. The Substring (6, 2)=="00")
{
String data=https://bbs.csdn.net/topics/str.Substring (1, STR. Length - 1);
List. The Add (data);
}
STR=sr. ReadLine ();
}
The sr. The Close ();
Fs. The Close ();
}
The catch (Exception ex)
{
Console. WriteLine (" [ERROR] "+ ex. Message. The ToString ());
}
return list;
}
Per click a button to invoke a getTextList, such as good 5 seconds then click, when click a third time:
The catch (Exception ex)
{
Console. WriteLine (" [ERROR] "+ ex. Message. The ToString ());
}
The exception is caught,
CodePudding user response:
Are you sure the while (STR!=string. The Empty) is not an infinite loop? Generally the sr. ReadLine () no, value is null, you can use the while (! String. IsNullOrEmpty (STR)) have a try,CodePudding user response:
Only read the words, a file opened in read-only modeFileStream stream=new FileStream (" path ", FileMode. Open, FileAccess. Read, FileShare. Read);
CodePudding user response:
Why bother?String [] a=File. ReadAllLines (FileName);
Or;
Var list=File. ReadAllLines (FileName) ToList ();
How simple!