Java——Read/convert an InputStream to a String
获取 InputStream 并将其转换为String的简单方法。
添加commons-io-2.4.jar
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils; public class StringFromFile { public static void main(String[] args) throws IOException {
InputStream inputStream = StringFromFile.class.getResourceAsStream("2.txt");
String myString = IOUtils.toString(inputStream, "UTF-8"); System.out.println(myString); } }
来源: http://stackoverflow.com/questions/309424/read-convert-an-inputstream-to-a-string
Java——Read/convert an InputStream to a String的更多相关文章
- Java 把 InputStream 转换成 String 的几种方法
我们在 Java 中经常会碰到如何把 InputStream 转换成 String 的情形,比如从文件或网络得到一个 InputStream,需要转换成字符串输出或赋给别的变量. 未真正关注这个问题之 ...
- Java 里把 InputStream 转换成 String 的几种方法
我们在 Java 中经常会碰到如何把 InputStream 转换成 String 的情形,比如从文件或网络得到一个 InputStream,需要转换成字符串输出或赋给别的变量. 未真正关注这个问题之 ...
- Java中将InputStream读取为String, 各种方法的性能对比
如下, 一共存在11种实现方式及其对应的性能测试结果: 1. 使用IOUtils.toString (Apache Utils) String result = IOUtils.toString(in ...
- Java 8 – Convert Map to LIST
Java 8 – Convert Map to LIST Few Java examples to convert a Map to a List Map<String, String> ...
- Java 8 – Convert List to Map
Java 8 – Convert List to Map package com.mkyong.java8 public class Hosting { private int Id; private ...
- Java 8 – Convert a Stream to LIST
Java 8 – Convert a Stream to LIST package com.mkyong.java8; import java.util.List;import java.util.s ...
- InputStream转化为String
参考:https://blog.csdn.net/lmy86263/article/details/60479350 eg: InputStream in = PropertiesUtils.cla ...
- Java中调用c/c++语言出现Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/String;)V...错误
错误: Exception in thread "main" java.lang.UnsatisfiedLinkError: Test.testPrint(Ljava/lang/S ...
- JAVA之旅(十六)——String类,String常用方法,获取,判断,转换,替换,切割,子串,大小写转换,去除空格,比较
JAVA之旅(十六)--String类,String常用方法,获取,判断,转换,替换,切割,子串,大小写转换,去除空格,比较 过节耽误了几天,我们继续JAVA之旅 一.String概述 String时 ...
随机推荐
- onethink框架显示Access denied for user 'root'@'localhost' (using password: NO)
本地开发的时候使用的用户名是root,密码为空,它会生成两份.一份在Common/config.php里面,还有一份在Application\User\Conf/config.php 在linux环境 ...
- Delegate(QLabel和QComboBox)
一.最终效果 二.实现思路 1.createEditor()中create两个控件,分别是QLabel和QComboBox,将其添加到一个widget中,然后返回该widget: 2.setEdito ...
- ACM hust 2.1
来自咸鱼王的呻吟 http://www.xiami.com/song/3599639?spm=a1z1s.3521865.23309997.1.PbLu7E 配合咸鱼食用效果更佳(右键新窗口打开) 题 ...
- jspSmartUpload上传下载使用例子
--------------------------------------------------------------------- ServletUpload.java 上传 package ...
- Alpha-5
前言 失心疯病源5 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 14:30~15:30 阅读blob分析相关论文,找到一篇很早年的论文,但是作者讲解十分细 ...
- 将MathType公式转换为LaTex格式
LaTex编辑公式不够直观,常常会因为结构复杂导致数据或者符号出错,使用MathType编辑公式后再直接转换成LaTex代码可以避免这个问题. 一.首先在MathType中编辑公式 二.然后点击参数— ...
- Kprobe
linux内核源码Documentation目录下存在kprobe介绍文档如下 Kprobes allows multiple probes at the same address. Current ...
- <Effective C++>读书摘要--Inheritance and Object-Oriented Design<一>
1.Furthermore, I explain what the different features in C++ really mean — what you are really expres ...
- CentOS 6安装thrift支持erlang开发
早前,在我的博文thrift多平台安装介绍了如何在debian/ubuntu下面安装thrift,并支持erlang开发的.而在CentOS平台下,并没有成功安装.经过不断摸索,终于成功了,这篇博文就 ...
- laravel 可用验证规则
accepted 验证的字段必须为 yes. on. 1.或 true.这在确认服务条款是否同意时相当有用. active_url 相当于使用了 PHP 函数 dns_get_record,验证的字段 ...