0

please someone help me , i try read arabic string from json file

the code i use it , i try read multi-lines of arabic language

public String loadJSONFromAsset() {
        String json = null;
        try {

            InputStream is = getAssets().open("horo_scop.txt");
            int size = is.available();
            byte[] buffer = new byte[size];
            is.read(buffer);
            is.close();
            json = new String(buffer, "UTF_8");

            System.out.println("horo json file " + json);

        } catch (IOException ex) {
            ex.printStackTrace();
            return null;
        }
        return json;

    }

it print arabic like that "????? ???"

how can i fix it

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
  • What encoding is used when saving the horo_scop.txt file? Assuming that file contains the correct text you need to read it using the same encoding. – Squonk Aug 17 '14 at 07:17
  • Try setting the text on TextView instead of SysOut. And also for logging use Log.* classes. Quit use of SysOut and other java console streams. – Rohit Sharma Aug 17 '14 at 07:18
  • i dont encode when i save file , it enocde when i read it i do print it in textview – Mina Fawzy Aug 17 '14 at 07:27
  • @user3240583 : In order to store arabic characters a text file must use some form of encoding - a basic "plain text" file will only support ASCII characters. Whatever you're using to save it must be using one of the character-set encodings such as Unicode etc. It's most likely that whatever it's saved in, is not the same encoding as the one you're using to read it back. – Squonk Aug 17 '14 at 08:08
  • what's android ver you support? – Muhammed Refaat Aug 17 '14 at 08:33

0 Answers0