Home Android - How to read txt file in JAVA
Reply: 3

Android - How to read txt file in JAVA

Syrian I-Iacker
1#
Syrian I-Iacker Published in 2017-11-14 23:08:39Z

Please Will some one help me out i am trying to read an Arabic .txt file and it always give me the Arabic word like this "????? ???"

private String ReadArabic() {

    String words="";
    try {
        InputStream stream = getAssets().open("arabwords.txt");

        int size = stream.available();
        byte[] buffer = new byte[size];
        stream.read(buffer);
        stream.close();
        words = new String(buffer, "UTF-8");
        words = words.replaceAll("(\\r|\\n)", "");
    } catch (IOException e) {
        // Handle exceptions here
    }
    return words;
}
diegoveloper
2#
diegoveloper Reply to 2017-11-15 01:22:19Z

Try using: "cp864" instead of "UTF-8"

premkamal008
3#
premkamal008 Reply to 2017-11-14 23:28:45Z

Its possible that your console is not set to properly display UTF-8 characters.

The configuration of that depends on the IDE. You might need to configure the same there.

Tom Jowitt
4#
Tom Jowitt Reply to 2017-11-15 23:45:19Z

it worked by using "cp1256" Thanks Evey one

private String ReadArabic() {

    String words="";
    try {
        InputStream stream = getAssets().open("arabwords.txt");

        int size = stream.available();
        byte[] buffer = new byte[size];
        stream.read(buffer);
        stream.close();
        words = new String(buffer, "cp1256");
        words = words.replaceAll("(\\r|\\n)", "");
    } catch (IOException e) {
        // Handle exceptions here
    }
    return words;
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.320419 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO