The student list is stored in Notepad, and a student's name is written on one line
Read Notepad files through FileStream, StreamReader, and store the contents in a DataTable
<summary>
///DataTable Display selected student list
///</summary>
///<returns></returns> Public
static DataTable stulist ()
{
DataTable dt = new DataTable ();
Dt. Columns.Add ("Student name");
String Sfilepath = String. Empty;
The path of the student list
Sfilepath = Parameters.g_sstulistpath + Frm.cblClass.SelectedItem;
Determine if the student list exists if
(! File.exists (Sfilepath))
{
MessageBox.Show ("The Student list file does not exist, please check for errors.") ");
return dt;
}
String sstuname = String. Empty;
FileStream fs = new FileStream (Sfilepath, FileMode.Open);
"GB2312" is used to display Chinese characters, to write other words, will display garbled
StreamReader reader = new StreamReader (FS, unicodeencoding.getencoding (" GB2312 "));
One line reads while
(sstuname = reader. ReadLine ())!= null)
{
sstuname = Sstuname.trim (). ToString ();
DataRow dr = dt. NewRow ();
dr["Student Name" = Sstuname;
Dt. Rows.Add (DR);
}
m_dtstu = DT;
Closes the file stream
fs. Close ();
return DT;
}