StringUtil工具类
来源:互联网 发布:珠光宝气人物分析知乎 编辑:程序博客网 时间:2024/05/22 04:52
package com.bwei.ydhl.utils;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by muhanxi on 17/4/3.
*/
public class StringUtils {
public static String inputStreamToString(InputStream inputStream) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int length = 0;
while ((length = inputStream.read(buf)) != -1) {
byteArrayOutputStream.write(buf, 0, length);
}
return new String(byteArrayOutputStream.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String inputStraemToStringBuffer(InputStream inputStream) {
StringBuilder stringBuilder = new StringBuilder();
try {
String line = null;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
return stringBuilder.toString();
}
}
}
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* Created by muhanxi on 17/4/3.
*/
public class StringUtils {
public static String inputStreamToString(InputStream inputStream) {
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int length = 0;
while ((length = inputStream.read(buf)) != -1) {
byteArrayOutputStream.write(buf, 0, length);
}
return new String(byteArrayOutputStream.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String inputStraemToStringBuffer(InputStream inputStream) {
StringBuilder stringBuilder = new StringBuilder();
try {
String line = null;
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
return stringBuilder.toString();
}
}
}
0 0
- Flex StringUtil工具类
- java StringUtil 工具类
- 工具类StringUtil.java
- StringUtil工具类
- 工具类StringUtil
- StringUtil工具类
- StringUtil工具类
- StringUtil工具类
- StringUtil 字符串工具类
- java StringUtil 工具类
- StringUtil(字符串工具类)
- StringUtil工具类解析
- StringUtil工具类
- 字符串工具类 StringUtil.java
- StringUtil 工具类 过滤作用
- android 工具类篇 StringUtil
- J2EE工具类:StringUtil.java
- 定义字符串工具类StringUtil
- 为什么要实现Serializable
- mysql优化——show status详解
- kafka阻塞排错步骤
- nyoj 1242 Interference Signal(暴力枚举)
- 字符设备驱动(二)
- StringUtil工具类
- java范型
- 网络状态工具类
- PHP:self::和$this->的区别
- 连续的性质与定义
- [leetCode刷题笔记]46. Permutations
- 概率论与数理统计_陈希儒版_第一章:事件的概率
- 读Php-simple-cas笔记(1)
- SQL SERVER中求上月、本月和下月的第一天和最后一天