回答: intをファイルに直接書き込むことはできません。最初に文字列に変換します。
元の質問:
これはおかしな質問のように聞こえるかもしれませんが、他に方向転換する場所はありません。
Javaにエポック(タイムスタンプ)を.sessionファイルに書き込ませようとしています(尋ねないでください)。何もしていないようです。これが私が持っているものです:
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();
}
はい、メソッドはIOExceptionをスローするように宣言されています(実行時に発生するものはありません)。問題は、私が書いている.sessionファイルが常に空になることです。私は間違って洗い流していますか?これに光を当てるのを手伝ってください。御時間ありがとうございます。
参考:エポックは、私が行ったように正しく計算されSystem.out.println(GetTimestamp())
ます。
GetTimestamp()はMYメソッドです。静的です。