java - Trouble writing 's into a .txt file, using FileOutputStream -
the problem when read string , then, try write each characters in separate line, .txt
file, although system.out.println
show correct characters, when write them .txt
file, 's
write weird characters instead. illustrate, here example: suppose have line second subject’s layout of same 100 pages.
, want write .txt
file, using following code:
public static void write(string swrite) throws ioexception { if(!file.exists()){ file.createnewfile(); } fileoutputstream fop=new fileoutputstream(file,true); if(swrite!=null) for(final string s : swrite.split(" ")){ fop.write(s.tolowercase().getbytes()); fop.write(system.getproperty("line.separator").getbytes()); } fop.flush(); fop.close(); }
the written file word, subject's
: subject̢۪s
. have no idea why happens.
try following. frees having deal character encoding.
printwriter pw = null; try { pw = new printwriter(file); if (swrite!=null) (string s : swrite.split(" ")) { pw.println(s); } } } { if (pw != null) { pw.close(); } }
Comments
Post a Comment