Search code examples
androidandroid-networking

How to download String file which contain special characters of slovenia


I am trying to download the json file which contains slovenian characters,While downloading json file as a string I am getting special character as specified below in json data

"send_mail": "Po�lji elektronsko sporocilo.",
"str_comments_likes": "Komentarji, v�ecki in mejniki",

Code which I am using

URL url = new URL(f_url[0]);
URLConnection conection = url.openConnection();
conection.connect();
try {
    InputStream input1 = new BufferedInputStream(url.openStream(), 300);
    String myData = "";
    BufferedReader r = new BufferedReader(new InputStreamReader(input1));
    StringBuilder totalValue = new StringBuilder();
    String line;
    while ((line = r.readLine()) != null) {
        totalValue.append(line).append('\n');
    }
    input1.close();
    String value = totalValue.toString();
    Log.v("To Check Problem from http paramers", value);
} catch (Exception e) {
    Log.v("Exception Character Isssue", "" + e.getMessage());
}

I want to know how to get characters downloaded properly.


Solution

  • I finally found this way which worked for me

    InputStream input1 = new BufferedInputStream(conection.getInputStream(), 300);
    
    BufferedReader r = new BufferedReader(new InputStreamReader(input1, "Windows-1252"));
    

    I figured out by this windows-1252, by putting json file in asset folder of the android application folder, where it showed same special characters like specified above,there it showed auto suggestion options to change encoding to UTF-8,ISO-8859-1,ASCII and Windows-1252, So I changed to windows-1252, which worked in android studio which i replicated the same in our code, which worked.