I have written this code in eclipse to get some arabic words and then print them
public class getString {
public static void main(String[] args) throws Exception {
PrintStream out = new PrintStream(System.out, true, "UTF-8");
Reader r = new InputStreamReader(System.in, "UTF-8");
char[] str ;
str= new char[10];
r.read(str);
out.println(str);
}
}
but the output is this:
شیرین
شیرین
any help??
thanks in advance for your attention
I would try this setup:
This is how I used to create IO to handle non-latin characters. Note that this has no auto-flush.
Just set workspace encoding to UTF-8 by Window > Preferences > General > Workspace > Text File Encoding. This also affects the encoding of the stdout in Eclipse console.
Then you can also just replace
new PrintStream(System.out, true, "UTF-8")
bySystem.out
.Since you are using windows, then this is how you set encoding as UTF 8 in eclipse:
1- Open Run Dialog > select "your java application" > Common Tab > Encoding > Other > "set it to UTF-8"
2- Open Run Dialog > select "your java application" > Arguments Tab > VM Arguments > Add "-Dfile.encoding=UTF-8"
3- Open Window Menu > General > Workspace > Text file encoding should be set to "UTF-8"
Then you can run your application.