输入流转字符串

public static String InputStream2String(InputStream in) {
	InputStreamReader reader = null;
	try {
		reader = new InputStreamReader(in, "UTF-8");
	} catch (UnsupportedEncodingException e1) {
		e1.printStackTrace();
	}
	BufferedReader br = new BufferedReader(reader);
	StringBuilder sb = new StringBuilder();
	String line = "";
	try {
		while ((line = br.readLine()) != null) {
			sb.append(line);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	return sb.toString();
}

  

字符串转输入流

public static InputStream String2InputStream(String str) {
	ByteArrayInputStream stream = null;
	try {
		stream = new ByteArrayInputStream(str.getBytes("UTF-8"));
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	return stream;
}

  

相关文章:

  • 2021-06-03
  • 2021-11-02
  • 2022-02-19
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-05-29
  • 2022-12-23
猜你喜欢
  • 2021-06-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案