Sign in to follow this  
mdog

[java] text file question

Recommended Posts

I want to add a string to a text file without overwriting the text that is already there. It should just add another line. This doesn't work: try { PrintStream out = new PrintStream(file); String scores = "NAME: "+name+" TIME: "+timer; out.append(scores); } catch (Exception e) { e.printStackTrace(); }

Share this post


Link to post
Share on other sites
Try this instead (careful, though - I don't use Java[smile]):

try {
BufferedWriter out = new BufferedWriter(new FileWriter(file, true));
String scores = "NAME: " + name + " TIME: " + timer;
out.write(scores);
out.close();
} catch (IOException e) {
// your error handler goes here.
}



HTH,
Pat

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this