这是我的网络服务响应..
Testperson-se,Approved,Stårgatan 1,12345,Ankeborg,SE
现在在 Stårgatan 的这个字符串中有一个带点的特殊字符,当我打印此响应时它给我问号字符串,例如 ..
Testperson-se,Approved,St?rgatan 1,12345,Ankeborg,SE
我使用以下代码。
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 "";
}
}
如何打印这个特殊字符?
最佳答案
您可能希望使用 InputSource#getEncoding 返回的编码
Get the character encoding for a byte stream or URI. This value will be ignored when the application provides a character stream.
关于android - 如何在android中打印特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12602598/