내가 여기 튜토리얼을 따라 작동하지 쓰기자바의 FileOutputStream은
File scoreFile = new File("score.txt");
if(!scoreFile.exists()) {
scoreFile.createNewFile();
}
oFile = new FileOutputStream(scoreFile, false);
oFile.write("Score = 1".getBytes());
oFile.flush();
oFile.close();
을하지만 아무것도 파일 score.txt에 기록되지되고있다.
편집 : 전체 기능이 아래와 같습니다 :
// Set win or loose to score.dat.
public void setScore(boolean won, boolean reset){
out.println("setScore()");
long timePassed = (timeEnd - timeStart)/1000; // Seconds passed.
double[] prevScore = getScore(); // get previous score (Won, Lost).
// Create a writer to edit the file.
File scoreFile = new File("score.txt");
if(!scoreFile.exists()) {
try {
scoreFile.createNewFile();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(!reset){
if(won){
// Add time to Win values.
prevScore[0] += timePassed;
}
else{
// Add time to Lost values.
prevScore[1] += timePassed;
}
try {
FileOutputStream oFile = new FileOutputStream(scoreFile, false);
// Write new score.
byte[] contentBytes = (String.valueOf(prevScore[0]+" "+prevScore[1])).getBytes();
oFile.write("Bye".getBytes());
oFile.flush();
oFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else{
// If battle ended, delete the scores.
FileOutputStream oFile;
try {
if(!scoreFile.exists()) {
scoreFile.createNewFile();
}
oFile = new FileOutputStream(scoreFile, false);
oFile.write("Error".getBytes());
oFile.flush();
oFile.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
나는이 파일을 작성 볼 수 있기 때문에 파일이 생성된다 알고 있지만, 어떤 텍스트를 채우지 않습니다.
당신은 좋은 score.txt 파일에서 찾고 계십니까? scoreFile.getAbsolutePath()를 sysout으로 시도해보십시오. 이렇게해도 문제가 해결되지 않으면 SSCCE (http://sscce.org) –
게시 이유는 무엇입니까? 콘텐츠를 가져 와서 버리는 이유는 무엇입니까? – gawicks