简体   繁体   中英

Android: Trying to read a word in another language other than english

I have a scanner which uses the method s.next(); (it reads a whole word separates by " ") it works fine with English letters and words, but when I write something in Hebrew, it returns "??" instead.

My Phone does have the Hebrew language, all other strings in my app are in Hebrew, only what the scanner reads returns ?????.

Any Help? Thanks :)

The scanner code: (it's part of an asynctask)

@Override
    protected Void doInBackground(CharSequence... txt) {
        Scanner s = new Scanner(getResources().openRawResource(R.raw.data));
        try {
            boolean add;
            do { 
                add = false;
                ListItem temp = new ListItem();
                temp.data[ListItem.NAME] = s.next();
                Log.i("AsyncTask", temp.data[ListItem.NAME]);
                if (temp.data[ListItem.NAME].contains(txt[0])) {
                    Log.i("match", "found");
                    add = true; 
                }
                temp.data[ListItem.MAKAT] = s.next();
                Log.i("AsyncTask", temp.data[ListItem.MAKAT]);
                if (temp.data[ListItem.MAKAT].contains(txt[0])) {
                    add = true; 
                }
                temp.data[ListItem.JHAZIT] = s.next();
                temp.data[ListItem.KOMA] = s.next();
                temp.data[ListItem.MESPAR] = s.next();

                if (add) {
                    this.publishProgress(temp);
                }
            }
            while (s.hasNext());

        }
        finally {
            s.close();
        }
        return null;
    }

And the file i take out the info is named data.txt :

Barrel 4315124 2 3 43
car 414124 2 4 41
Red_box 4315124 1 2 77
Glass_cup 4515124 4 7 10
Iron_cup 4515124 4 7 9
Gabi_Noob 5717217 7 8 9 מכסה_גומי 46245897235 8 9 10

Well, Actually using the UTF-8 encoding like it was mention in the comments worked, only i had to create the data.txt using a notepad outside of eclipse and save it with UTF-8 encoding instead of the ANSI(default) than i simply imported it inside the eclipse where the raw folder, clicked run and it worked. MAGIC.

i guess my mistake was to create the data.txt from inside eclipse.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM