FileWriter in java not writing to txt file -
this question has reply here:
bufferedwriter not writing output file 7 answersi trying input joptionpane
, store user typed text file using filewriter
class.to create sure input user typed beingness stored wrote system.out , typed in joptionpane appears. unfortunately when open .txt file nil entered appears! way, file path entered correct.
here code. help me!
string playername = joptionpane.showinputdialog("what character's name?"); system.out.println(playername); seek { filewriter charectersname = new filewriter("/users/alecstanton/desktop/name.txt/"); bufferedwriter out = new bufferedwriter(charectersname); out.write(playername); } grab (ioexception e) { // todo auto-generated grab block e.printstacktrace(); }
buffered writers write out when they're total or when they're beingness closed (hence name buffered).
so can this:
out.close();
which flush buffer , close it. if wanted flush maintain open farther writes (e.g. imagine you're writing log file), do:
out.flush();
you'd want when finishing such resource. e.g.
bufferedwriter out = ... seek { out.write(...); } grab (exception e) { // .. } { out.close(); }
or perchance using try-with-resources constructs in java 7, (frankly) more reliable write code around.
java filewriter
No comments:
Post a Comment