java - How to set UTF-8 encoding for a file which opens on a seperate JFrame on a JTextPane -
i have separate class jframe, opens when user clicks button on main frame. frame has jtextpane displays content. open file code written below. in slovenia have letters don't show correctly (ex. grilled chicken = piščanec na žaru... š,č , ž show squares).
my question is, possible set utf-8 encoding text or file, without changing font? font has stay default (using netbeans).
public class editframe extends javax.swing.jframe { public void readfile(file f) { try { textpane.read(new java.io.filereader(f), null); } catch (ioexception ex) { logger.getlogger(editframe.class.getname()).log(level.severe, null, ex); } } ... }
you have specify encoding of file reading from.
it may done :
bufferedreader reader = new bufferedreader(new inputstreamreader(new fileinputstream(f), "utf-8")); textpane.read(reader, null);
Comments
Post a Comment