String类型转换成InputStream对象使用ByteArrayInputStream类
01.package org.kodejava.example.io;
02. 03.import java.io.ByteArrayInputStream; 04.import java.io.InputStream; 05.import java.io.UnsupportedEncodingException; 06. 07.public class StringToStream { 08. public static void main(String[] args) { 09. String text = "Converting String to InputStream Example"; 10. 11. /* 12. * Convert String to InputStream using ByteArrayInputStream 13. * class. This class constructor takes the string byte array 14. * which can be done by calling the getBytes() method. 15. */16. try { 17. InputStream is = new ByteArrayInputStream(text.getBytes("UTF-8")); 18. } catch (UnsupportedEncodingException e) { 19. e.printStackTrace(); 20. } 21. } 22.}
666

被折叠的 条评论
为什么被折叠?



