How can I read a String into an inputStream in Java?
本问题已经有最佳答案,请猛点这里访问。
Possible Duplicate:
How do I convert a String to an InputStream in Java?
如何在Java中读取字符串到输入流中?
我希望能够将
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | public class StringToInputStreamExample { public static void main(String[] args) throws IOException { String str ="This is a String ~ GoGoGo"; // convert String into InputStream InputStream is = new ByteArrayInputStream(str.getBytes()); // read it with BufferedReader BufferedReader br = new BufferedReader(new InputStreamReader(is)); String line; while ((line = br.readLine()) != null) { System.out.println(line); } br.close(); } } |
源代码:如何在Java中转换字符串到输入流
有点像…
1 |
应该工作…
对于一个
如果
1 |
您可以使用