Java中IOUtils
来源:互联网 发布:手机做广告软件 编辑:程序博客网 时间:2024/06/02 00:38
public class IOUtils
{
public static byte[] getByte(InputStream is) throws Exception
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1)
{
bos.write(buffer);
}
return bos.toByteArray();
}
public static String getString(InputStream is) throws Exception
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1)
{
bos.write(buffer);
}
return bos.toString().trim();
}
public static String read(String filename) throws Exception
{
FileInputStream fis = new FileInputStream(filename);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
// 将内容读到buffer中,读到末尾为-1
while ((len = fis.read(buffer)) != -1)
{
// 将每次读到字节数组(buffer变量)内容写到内存缓冲区中,起到保存每次内容的作用
outStream.write(buffer, 0, len);
}
byte[] data = outStream.toByteArray(); // 取内存中保存的数据
fis.close();
String result = new String(data, "UTF-8");
return result;
}
}
- Java中IOUtils
- IOUtils
- IOUtils
- IOUtils
- java IOUtils copy and flush client
- Tomcat中使用commons-io-2.5发生的错误java.lang.ClassNotFoundException- org.apache.commons.io.IOUtils
- java 实现下载htttp文件的简便办法 FileUtils IOUtils
- Java IO流学习总结八:Commons IO 2.5-IOUtils
- IOUtils API
- IOUtils总结
- 利用commons-io.jar包中FileUtils和IOUtils工具类操作流及文件
- NO.63 [file]IO常用工具类IOUtils(Java读文件、写文件、打Zip包)
- [file]IO常用工具类IOUtils(Java读文件、写文件、打Zip包)
- 10.10-全栈Java笔记:Apache IOUtils和FileUtils的使用
- jackec commons - FileUtils- IOUtils
- IOUtils-Dephi2010文件读取
- apache_commons_io中的IOUtils学习
- StringUtils、IOUtils and FileUtils
- android面试题:请介绍下Android中常用的五种布局
- linux中单引号、双引号、反引号的作用
- Eclipse中自动载入WEB-INF/lib下jar包的方法
- UISearchBar背景透明,去掉背景,自定义背景(转)
- OLTP和OLAP小结
- Java中IOUtils
- 十进制、十六进制、bcd互转
- 【Java Web】: 使用 Telnet 远程连接服务器端与 Tomcat 服务器的搭建
- android面试题:请介绍下Android的数据存储方式
- objc和java中一些endian、byte转换相关的细节
- Documentation/cgroups/net_cls
- ios set UINavigationBar background color
- golang 模拟登陆微信公众平台,突破微信群发每日一条限制
- 在 iOS 应用中直接跳转到 AppStore 的方法