InputStream is a super class of all classes representing an input stream of bytes. Here is one example to convert a String to InputStream.
Example
package com.pretech;import java.io.*;public class StringtoInputStream {public static void main(String[] args) throws IOException {//ConvertingInputStream ins = new ByteArrayInputStream("HelloWorld".getBytes());//ReadingBufferedReader reader = new BufferedReader(new InputStreamReader(ins));String line;while ((line = reader.readLine()) != null) {System.out.println(line);}}}
Output
HelloWorld
No comments:
Post a Comment