The following code does not produce a file (I can't see the file anywhere). What is missing?
try {
//create a temporary file
String timeLog = new SimpleDateFormat("yyyyMMdd_HHmmss").format(
Calendar.getInstance().getTime());
File logFile=new File(timeLog);
BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
writer.write (string);
//Close writer
writer.close();
} catch(Exception e) {
e.printStackTrace();
}
writer.flush()
before you close it. 2- You should be using afinally
block to ensure that theWriter
is closed even if there is an exceptionSystem.out.println(logFile.getCanonicalPath());
just before you create the writer, this will tell you where the file is been written to.