This is simple exmaple for converting string object to a InputStream and then read it using the BufferedReader.
[code lang=”java”] package javabeat.net.core;import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class StringToInputStreamExample {
public static void main(String[] args) throws IOException {
String sampleString = "This is a example for String To InputStream";
// Convert String into InputStream using getBytes method
InputStream is = new ByteArrayInputStream(sampleString.getBytes());
// Read using BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
[/code]