Monday, June 18, 2012

Java IO : Convert String to InputStream

import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {
        String str = "Hello World";

        InputStream is = new ByteArrayInputStream(str.getBytes());

        BufferedReader br = new BufferedReader(new InputStreamReader(is));

        String line;
        while ((line = br.readLine()) != null) {
            System.out.println(line);
        }

        br.close();
    }
}

No comments:

Post a Comment