how to read and write in arabic in eclipse

10,467

Solution 1

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.

enter image description here

Then you can also just replace new PrintStream(System.out, true, "UTF-8") by System.out.

Solution 2

I would try this setup:

BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out, "UTF-8"));
BufferedReader in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));

String input = in.readLine();
out.write(input);
out.write("\n");
out.flush();

This is how I used to create IO to handle non-latin characters. Note that this has no auto-flush.

Solution 3

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"

enter image description here

2- Open Run Dialog > select "your java application" > Arguments Tab > VM Arguments > Add "-Dfile.encoding=UTF-8"

enter image description here

3- Open Window Menu > General > Workspace > Text file encoding should be set to "UTF-8"

enter image description here

Then you can run your application.

Share:
10,467
Linda
Author by

Linda

Updated on June 04, 2022

Comments

  • Linda
    Linda almost 2 years

    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