Search code examples
javaandroidandroid-emulatorbufferedreaderandroid-fonts

apostrophe symbol, euro sign and pound sign not fetching exactly from remote text file


In my android application i am fetching the content of text file from a remote location. The code is below

        URL textUrl;
        try {
        textUrl = new URL("http://myurl/data.txt");
        BufferedReader bufferReader = new BufferedReader(
                new InputStreamReader(textUrl.openStream()));
        String StringBuffer;

        while ((StringBuffer = bufferReader.readLine()) != null) {

            list.add(StringBuffer);

        }
        bufferReader.close();

    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }

    return list;

My issue is i am not getting the exact data.The data in the file is

USA|US 100’s/50’s|1.23|| 0 |

|US $ 20/10/5|1.23|1.259| 0 |1.259

|USTC|0.00|0.00| 0 |0.00

JPN|Japan Yen 1,000|1.20|1.247| 0 |0.00

GBP|GBP £ 1 |2.08|2.116| 0 |0.00

EUR|Euro € 1 unit|1.705|1.731| 0 |0.00

And the data i am getting is

USA|US 100�s/50�s|1.23|| 0 |

|US $ 20/10/5|1.23|1.259| 0 |1.259

|USTC|0.00|0.00| 0 |0.00

JPN|Japan Yen 1,000|1.20|1.247| 0 |0.00

GBP|GBP � 1 |2.08|2.116| 0 |0.00

EUR|Euro � 1 unit|1.705|1.731| 0 |0.00

The apostrophe symbol, euro sign and pound sign are replaced by � symbol.

I am getting the same result in both emulator and device.

I can not do anything in the remote txt file.

How can i get the exact data?


Solution

  • I found the solution.

    1) Figure out the encoding used in the file, as @laalto said . Here the encoding was "windows-1252".

    2)Then edited the code as

     BufferedReader bufferReader = new BufferedReader(new InputStreamReader(textUrl.openStream(), "windows-1252"));
    

    It is working fine for me.