0
問題:我需要刪除保留。用戶通過SimpleInOutDialog給我預留的時間。然後,如果文件包含該小時,我使用緩衝讀取器進行搜索。使用java在txt文件中刪除一行和下面的2行
我需要做的是刪除那條線,下面有小時和2條線,因爲有保留的數據。下面是和例子txtfile註冊表中:
10:00
Niel Butaye
1
09:00
Tom Mullue
2
所以我找10:00和10:00,然後,尼爾Butaye和1個需要被刪除。 我已經有了代碼:
public void setAnnulation() {
//make SimpleInOutDialog
SimpleInOutDialog input = new SimpleInOutDialog("Delete reservation");
reservation= input.readString("Give the hour (hh:mm)");
try{
BufferedReader br = new BufferedReader(new FileReader("L:\\Documents/Informatica/6de jaar/GIP/Reservations.txt"));
HashSet<String> hs = new HashSet<String>();
int i = 0;
while ((line = br.readLine()) != null)
{
i++;
hs.add(br.readLine());
}
if(hs.contains(reservation)){
//klant bestaat
input.showString("The Reservation is being deleted", "");...}
}catch (Exception e){//Catch wanneer er errors zijn
System.err.println("Error: " + e.getMessage());}
}
,其中「...」需要拿出的代碼。任何幫助?
你見過這個答案嗎? http://stackoverflow.com/questions/2471330/delete-a-line-from-a-file-in-java – 2012-03-10 15:30:17