ANSWER: You cannot write an int directly to a file. Convert it to a string first.
Original Question:
I know that this may sound like a nooby question, but I have nowhere else to turn.
I'm trying to make Java write the Epoch (timestamp) to a .session file (don't ask). It doesn't seem to do anything. Here is what I have:
gamesession = new File(SESSION_LOCATION); // Sets the .session file
if(gamesession.exists()){
gamesession.delete();
gamesession.createNewFile();
FileWriter stream = new FileWriter(SESSION_LOCATION);
BufferedWriter out = new BufferedWriter(stream);
out.write(GetTimestamp());
out.flush();
} // These blocks write the Epoch to the .session file for later time
else{
gamesession.createNewFile();
FileWriter stream = new FileWriter(SESSION_LOCATION);
BufferedWriter out = new BufferedWriter(stream);
out.write(GetTimestamp());
out.flush();
}
Yes, the method is DECLARED to throw a IOException (none occurs @ runtime). The problem is that, the .session file I'm writing to always turns up empty. Am I flushing wrong? Please help me shine some light on this. Thanks for your time.
FYI: The Epoch is calculated correctly, as I did System.out.println(GetTimestamp())
.
GetTimestamp() is MY method. It is static.