/**
* 導入方法
* @throws IOException
* @throws ParseException
*/
public void Import() throws IOException, ParseException {
FileReader FileR = new FileReader("D:\\File\\ut.txt");
BufferedReader BufferedR = new BufferedReader(FileR);
String Imp = BufferedR.readLine();
String[] SS = Imp.split("\t");
list.clear();
while (Imp != null) {
// String轉換Byte
byte Byteh = Byte.parseByte(SS[2]);
// String轉換Date
Date se = T.parse(SS[4].trim());
Date sr = T.parse(SS[5].trim());
// String轉換int
int Num = Integer.parseInt(SS[0]);
// 添加
Students S = new Students(Num, SS[1].trim(), Byteh, SS[3].trim(),
se, sr);
list.add(S);
System.out.println(Imp);
System.out.println(Imp);
Imp = BufferedR.readLine();
}
BufferedR.close();
FileR.close();
}
/**
* 導出方法
* @throws IOException
*/
public void Export() throws IOException {
System.err.println("正在導出......");
File F = new File("" + "D:\\File\\ut.txt");
OutputStream Q = new FileOutputStream(F, false);
// byte[] ru =
// ("學生ID|"+"學生姓名|"+"學生年齡|"+"學生性別|"+"創建時間|"+"修改時間\r\n").getBytes();
// Q.write(ru);
for (int i = 0; i < list.size(); i++) {
Students SS = (Students) list.get(i);
byte[] v = (i + 1 + "\t" + SS.getName() + "\t" + SS.getAge() + "\t"
+ SS.getGenber() + "\t" + T.format(SS.getTime()) + "\t"
+ T.format(SS.getXtime()) + "\r\n").getBytes();
Q.write(v);
}
Q.close();
System.err.println("導出完畢");
}
Java I/0文件(txt)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.