/**
* 利用BufferedReader实现Inputstream转换成String <功能详细描述>
*
* @param in
* @return String
*/ public static String Inputstr2Str_Reader(InputStream in, String encode)
{ String str = "";
try
{
if (encode == null || encode.equals(""))
{
// 默认以utf-8形式
encode = "utf-8";
}
BufferedReader reader = new BufferedReader(new InputStreamReader(in, encode));
StringBuffer sb = new StringBuffer(); while ((str = reader.readLine()) != null)
{
sb.append(str).append("\n");
}
return sb.toString();
}
catch (UnsupportedEncodingException e1)
{
e1.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
} return str;
} /**
* 利用byte数组转换InputStream------->String <功能详细描述>
*
* @param in
* @return
* @see [类、类#方法、类#成员]
*/ public static String Inputstr2Str_byteArr(InputStream in, String encode)
{
StringBuffer sb = new StringBuffer();
byte[] b = new byte[1024];
int len = 0;
try
{
if (encode == null || encode.equals(""))
{
// 默认以utf-8形式
encode = "utf-8";
}
while ((len = in.read(b)) != -1)
{
sb.append(new String(b, 0, len, encode));
}
return sb.toString();
}
catch (IOException e)
{
e.printStackTrace();
}
return ""; } /**
* 利用ByteArrayOutputStream:Inputstream------------>String <功能详细描述>
*
* @param in
* @return
* @see [类、类#方法、类#成员]
*/
public static String Inputstr2Str_ByteArrayOutputStream(InputStream in,String encode)
{
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] b = new byte[1024];
int len = 0;
try
{
if (encode == null || encode.equals(""))
{
// 默认以utf-8形式
encode = "utf-8";
}
while ((len = in.read(b)) > 0)
{
out.write(b, 0, len);
}
return out.toString(encode);
}
catch (IOException e)
{
e.printStackTrace();
}
return "";
} /**
* 利用ByteArrayInputStream:String------------------>InputStream <功能详细描述>
*
* @param inStr
* @return
* @see [类、类#方法、类#成员]
*/
public static InputStream Str2Inputstr(String inStr)
{
try
{
// return new ByteArrayInputStream(inStr.getBytes());
// return new ByteArrayInputStream(inStr.getBytes("UTF-8"));
return new StringBufferInputStream(inStr);
}
catch (Exception e)
{
e.printStackTrace();
}
return null;
}

最新文章

  1. Mac OS X上编写 ASP.NET vNext(一)KRE环境搭建
  2. 不同环境下文件上传Uncaught SyntaxError: Unexpected end of input
  3. thinkphp加载 和url_model
  4. UNIX环境高级编程笔记之进程控制
  5. mysqldump命令的常用组合
  6. Linux基础入门学习笔记20135227黄晓妍
  7. MySQL的left join中on与where的区别
  8. exe4j中&quot;this executable was created with an evaluation错误解决方法
  9. POJ2836 Rectangular Covering(状压DP)
  10. c#中的常用ToString()方法总结
  11. css style与class之间的区别,cssclass
  12. Python Learning
  13. STL Traits编程技法
  14. asp.net MVC FileResult在IE下异常的解决办法
  15. HTML5 File api 实现断点续传
  16. JSON序列化类
  17. ios可视化编程 UI高级 UI_13
  18. (7)STM32使用HAL库实现RS485通讯(全双工串口)
  19. 【设计模式】工厂方法模式 Factory Method Pattern
  20. XXXX is not in the sudoers file. This incident will be reported解决方法

热门文章

  1. C# ashx生成的验证码
  2. oracle 分布式数据库
  3. CSS3 Transitions
  4. FileWriter
  5. T-SQL表联接查询
  6. debug 输出 以及宏定义--备
  7. STL,ATL,WTL的联系与区别
  8. RMAN-06023: no backup or copy of datafile 6 found to restore
  9. 优秀的VeriSign和混蛋的GlobalSign
  10. Resharper TAB 傻吊