Read/convert an InputStream to a String
来源:互联网 发布:爱情不是毒药网络歌手 编辑:程序博客网 时间:2024/05/16 07:49
stackoverflow网站上的一个问题。
怎样用最简单的方法将inputstream转化为string类型?
比较好的答案:
public class InputStreamToString {public static void main(String[] args) {FileInputStream inputStream = null;StringWriter writer = null;try {inputStream = new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\cid.txt"));writer = new StringWriter();IOUtils.copy(inputStream, writer);String string = writer.toString();System.out.println(string);} catch (FileNotFoundException e1) {e1.printStackTrace();} catch (IOException e) {e.printStackTrace();}finally {try {inputStream.close();writer.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}
0 0
- Read/convert an InputStream to a String
- Convert a Java OutputStream to an InputStream
- Convert a Java OutputStream to an InputStream
- Convert a Java OutputStream to an InputStream
- Convert a Java OutputStream to an InputStream
- Convert a string to an enum
- Implement atoi to convert a string to an integer.
- Implement atoi to convert a string to an integer.
- How to convert InputStream to String/convert char[] to String
- 数字转换为字符串:String:convert an int to a string
- leetcode 8 Implement atoi to convert a string to an integer.
- convert a string to XmlElement
- Convert InputStream to JSONObject
- How Do I Convert an Integer to a String in Excel VBA
- convert List<String> to a String
- How to convert a String to DateTime
- Convert a String to a Number
- experiment : convert a string to crc32
- div 设置一行文字,文字超过后用...表示
- hihocoder #1318 : 非法二进制数
- 批量打包上传FIR脚本
- WGS84、GCJ02、BD911坐标相互转换
- mysql集群之MYSQL CLUSTER
- Read/convert an InputStream to a String
- 并查集-洛谷P1525 关押罪犯
- 有序广播
- 【Jmeter】——sql参数化查询测试
- bash中命令的扩展,使用``和$(),Command Substitution
- change事件触发失败的可能原因
- 通过httpClient访问第三方API
- 视音频编码简述
- 【React Native】Rreact Native 常见错误总结