Java Encoding Error -
i trying take string encoded , saved in cp1252 encoding , display in java text area. when read has black diamonds question marks special characters (', &, etc). should format display proper characters.
i cant copy , paste text displays when moved out of word. code using read cp1252 file below:
try { br = new bufferedreader(new filereader(f)); //read file line line while ((strline = br.readline()) != null) { emi.stringcontent += "\n" + strline; } br.close(); } catch (filenotfoundexception ex) { logger.getlogger(emailtmpdirread.class.getname()).log(level.severe, null, ex); } catch (ioexception ex) { logger.getlogger(emailtmpdirread.class.getname()).log(level.severe, null, ex); }
thanks!
made following edits , nothing reads in.
stringbuffer temp2 = new stringbuffer(1000); int numread = 0; char[] buf = new char[1024]; try { ir = new inputstreamreader(new fileinputstream(f), "cp1252"); while((numread = ir.read()) != -1) { string temp = string.valueof(buf, 0, numread); temp2.append(temp); buf = new char[1024]; } emi.stringcontent = temp2.tostring();
lines appear skipped stringbuffer temp2 = new stringbuffer();
try { ir = new inputstreamreader(new fileinputstream(f), "cp1252"); br = new bufferedreader(ir); while(br.readline() != null) { temp2.append(br.readline()); } emi.stringcontent = temp2.tostring();
rather using filereader
, use fileinputstream
wrapped inputstreamreader
; specify character encoding in inputstreamreader's constructor (according this page looks should use "cp1252" encoding)
Comments
Post a Comment