最近遇到一个问题,向服务器请求数据,然后将流读出来
不过,有时候读出来的数据里面会有乱码(/ □ \)
之前读流的方式是这样的
public static String getString(InputStream inputStream){
StringBuffer buffer = new StringBuffer();
if(inputStream != null){
byte[] b = new byte[4096];
try {
for (int n; (n = inputStream.read(b)) != -1;) {
buffer.append(new String(b, 0, n));
}
} catch (IOException e) {
e.printStackTrace();
}
}
return buffer.toString();
}
最后将读流方式是这样的
public static String getString(InputStream inputStream){
ByteArrayOutputStream outSteam = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int len = -1;