public static String getStringByUrl(String getUrl) {
// String getUrl =
StringBuffer sb = new StringBuffer();
InputStreamReader isr = null;
BufferedReader br = null;
try {
URL url = new URL(getUrl);
URLConnection urlConnection = url.openConnection();
urlConnection.setReadTimeout(60000);
urlConnection.setAllowUserInteraction(false);
/*isr = new InputStreamReader(url.openStream());*/
isr = new InputStreamReader(url.openStream(),Charset.forName("UTF-8"));
br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (isr != null) {
try {
isr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (br != null) {
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return sb.toString();
}
解决安卓SAX乱码
关注
打赏