Wednesday, May 16, 2012

read and write in java

I want print in the file every time line
But every time i want print a new line printed on the same line the old.



I want to print lines in the file



This my code



         BufferedReader read = new BufferedReader(new FileReader (SecurityScreen.path.get("ScoreFile")));
FileWriter file ;
BufferedWriter write = new BufferedWriter ( new FileWriter(SecurityScreen.path.get("ScoreFile")));
String temp = "" ;
String output = "";
String newLine = System.getProperty("line.separator");
String score= SecurityScreen.getPlayer() + "@" +gameTime + newLine;
// if(read.readLine()==null){
// write.write(score);
// }
try{
if((temp = read.readLine()) != null){

while (true) {
output += temp + newLine;
file = new FileWriter(SecurityScreen.path.get("ScoreFile"));
//write = new BufferedWriter(file);
write.write(output + newLine) ;
//score = SecurityScreen.getPlayer() + "@" +gameTime ;
write.write(score) ;
}
}
else {
write.write(score);
}

write.close();
}catch(IOException e){

}




No comments:

Post a Comment