I have a small Java project where I set the properties of class files in UTF-8 (I use a lot of foreign characters that are not found on CP1252 by default).
The goal is to create a text file (on Windows) containing a list of items. When starting class files from Eclipse itself (pressing Ctrl + F11) it creates the file flawlessly and opens it in another editor (I use Notepad ++). I can see the characters the way I wanted.
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Universidade2010 (18/18)β
β hidden: 0β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ€
But when I export the project (using Eclipse) as an executable Jar and run it using javaw -jar project.jar, the newly created file is a mess of question marks
????????????????????????????????????????????????????
? Universidade2010 (19/19)?
? hidden: 0?
????????????????????????????????????????????????????
, UTF-8 (, -, Java), ,
Writer w = new OutputStreamWriter(fos, "UTF-8");
, , Jar
- , Java , UTF-8 ?
, ( )
, ( Charset), :
public class Printer {
File f;
FileOutputStream fos;
Writer w;
final byte[] utf8_bom = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF };
public Printer(String filename){
f = new File(filename);
try {
fos = new FileOutputStream(f);
w = new OutputStreamWriter(fos, Charset.forName("UTF-8"));
fos.write(utf8_bom);
} catch (FileNotFoundException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
public void print(String s) {
if(fos != null){
try {
fos.write(s.getBytes());
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
:
private final char pipe = '\u2502';
private final char line = '\u2500';
private final char pipeleft = '\u251c';
private final char piperight = '\u2524';
private final char cupleft = '\u250c';
private final char cupright = '\u2510';
private final char cdownleft = '\u2514';
private final char cdownright = '\u2518';
, , Eclipse, , Jar ( "?" char)
, , Jar , , Eclipse CP1252 - , unicode