Reputation: 27
When I run my program from netbeans the Unicode looks fine. But when I run it from a compiled jar, it does not display correctly.
The following attempt did not fix it
Font font = new Font("Arial Unicode MS", Font.PLAIN, 16);
textarea.setFont(font);
// the two lines above were my attempt to fix the display, no luck
textarea.read( new FileReader( file.getAbsolutePath() ), null );
Here is the input text:
この文の長さは、Twitterの中で許容されるべきである。この文は長すぎない。この文はならず長すぎます。
Here is the result when I load that string from the program launched from the jar version:
Длина �того предложени� должны быть приемлемы в Twitter.
Upvotes: 0
Views: 689
Reputation: 33
I struggled with an analogous problem for so long I won't say. The following construct works fine INSIDE NetBeans 8.01 with jdk 8
String reconstituted;
//...
Charset charset = Charset.forName("UTF-8");
InputStream reconstitutedStream = new ByteArrayInputStream(reconstituted.getBytes(charset));
InputStreamReader ipsr = new InputStreamReader(reconstitutedStream);
But fails to display correct characters outside of ASCII range when run from jar file. Specifying the charset to the InputStreamReader constructor (like answer above, duh!! ) works both inside and outside NetBeans.
String reconstituted;
//...
Charset charset = Charset.forName("UTF-8");
InputStream reconstitutedStream = new ByteArrayInputStream(reconstituted.getBytes());
InputStreamReader ipsr = new InputStreamReader(reconstitutedStream, charset);
Upvotes: 0
Reputation: 14413
Not sure, but you should try with another Reader
to specify another charset.
Charset charset = Charset.forName("UTF-8");
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
textarea.read( reader , null );
Upvotes: 1