Reputation: 9507
Here is my webservice response..
Testperson-se,Approved,Stårgatan 1,12345,Ankeborg,SE
Now in this string at Stårgatan one special character a with dot is there when i print this response it give me question mark string like ..
Testperson-se,Approved,St?rgatan 1,12345,Ankeborg,SE
I use following code.
try {
URL url = new URL(
"http://www.ecodor.se/administrator/components/com_ivmstore/ivmwebservices/getaddress.php?pNumber=410321-9202"
);//
InputSource is = new InputSource(url.openStream());
StringBuffer res = new StringBuffer();
res.append(convertStreamToString(is.getByteStream()));
line = res.toString();
Log.i("==> responce", line);
//
} catch (Exception e) {
}
public String convertStreamToString(InputStream is) throws IOException {
/*
* To convert the InputStream to String we use the
* BufferedReader.readLine() method. We iterate until the BufferedReader
* return null which means there's no more data to read. Each line will
* appended to a StringBuilder and returned as String.
*/
if (is != null) {
StringBuilder sb = new StringBuilder();
String line;
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"));
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
} finally {
is.close();
}
return sb.toString();
} else {
return "";
}
}
How to print this special character?
Upvotes: 2
Views: 1298
Reputation: 9507
I solve it by using following.
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "ISO-8859-1"));
Thanks to all which give me idea.
Upvotes: 0
Reputation: 19185
You might want to use encoding returned by InputSource#getEncoding
Get the character encoding for a byte stream or URI. This value will be ignored when the application provides a character stream.
Upvotes: 1