我要從發佈文本文件中的日期看起來像什麼開始,這只是它的4行,實際上文件是幾百行。來自文本文件的條形數據
週五,2011年9月9日
-STV 101 -------- 05:00 - 23:59 SSB 4185報告印製2011年9月8日在2:37
0-AH 104 -------- 07:00 - 23:00 AH GYM Report打印於2011年9月8日2:37
-BG 105 -------- 07:00 - 23 :00 SH GREAT HALL Report打印於2011年9月8日2:37
我想用這個文本文件做的事情是忽略第一行的日期,然後忽略' - '下一行,但在「STV 101」,「5:00」和「23:59」中讀取將它們保存爲vari然後忽略該行上的所有其他字符,然後在每行後忽略。
這是我目前正在閱讀的完全線條。然後,只要用戶將路徑放入scheduleTxt JTextfield中,我就調用此函數。它可以讀取和打印每一行很好。
public void readFile() throws IOException
{
try
{
FileInputStream fstream = new FileInputStream(scheduleTxt.getText());
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null)
{
System.out.println (strLine);
}
in.close();
}
catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
UPDATE: it turns out I also need to strip Friday out of the top line and put it in a variable as well Thanks! Beef.
是的,在「0-AH 104 ----」的情況下,我只想要「AH 104」,謝謝,我會試試看看我得到了什麼! – Beef
更新:效果很好,用更廣泛的文本文件版本測試過,並且沒有問題,再次感謝 – Beef
我已經在答案上添加了關於表達式元素的解釋以供進一步參考 –