テキスト ファイルに書き込もうとしていますが、メソッドがファイルが存在しない場合はファイルを作成しますが、書き込みません。私は同様の問題を抱えた他のいくつかの投稿を経験し、アドバイスに従いましたが、運がありませんでした.
デバッガーを使用すると、文字列データには書き込む必要のある正しいデータが含まれますが、テキスト ファイルには書き込まれません。
私が見落としていたことについてのアドバイスをいただければ幸いです。
private static void createReservation(String filmName, String date, int noOfSeats, String username) {
FileWriter fw = null;
try {
File bookingFile = new File("C:\\server\\bookinginfo.txt");
if (!bookingFile.exists())
{
bookingFile.createNewFile();
}
fw = new FileWriter(bookingFile.getName(),true);
String data = "<"+filmName+"><"+date+"><"+Integer.toString(noOfSeats)+"><"+username+">\r\n";
fw.write(data);
fw.flush();
} catch (IOException ex) {
Logger.getLogger(FilmInfoHandler.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
fw.close();
} catch (IOException ex) {
Logger.getLogger(FilmInfoHandler.class.getName()).log(Level.SEVERE, null, ex);
}
}
}