DeltaDeuce
New Member
I am trying to write to a text file but even though the method creates the file if it does not exist, it does not write. I have been through several other posts with a similar issue and followed the advice but had no luck.Through use of the debugger, the String data contains the correct data that should be written but it is never written to the text file.Any advice on something I've overlooked would be appreciated.\[code\]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 = "http://stackoverflow.com/questions/15853656/<"+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); } }}\[/code\]