Java Outputstream to String
OutputStream存为String,OutputStream是输出流,用于输出文件内容,它本身不提供输入操作(也就是说没办法直接将OutputStream存为String)。下面是我找到的两个方法
// method 1:
// 从文件中获取的OutputStream
OutputStream os = new FileOutputStream(fileName);
OutputStreamWriter outw = null;
outw = new OutputStreamWriter(os);
String str = null;
outw.write(str);
outw.close();
os.flush();
os.close();
// method 2:
// 从文件中获取的OutputStream
OutputStream os = new FileOutputStream(fileName);
ByteArrayOutputStream baos=new ByteArrayOutputStream();
os.write(baos.toByteArray());
str = baos.toString();
os.flush();
os.close();
作者:skiffloveblue
补充:软件开发 , Java ,