get Stream via BufferedReader - Java File Path IO

Java examples for File Path IO:BufferedReader

Description

get Stream via BufferedReader

Demo Code

//package com.java2s;
import java.io.BufferedReader;

import java.io.ByteArrayInputStream;
import java.io.File;

import java.io.FileReader;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    public static void main(String[] argv) {
        String file = "Main.java";
        System.out.println(getStream(file));
    }//from   w w  w  .j a v a 2 s.  co  m

    public static InputStream getStream(String file) {
        File f = new File(file);
        String total = "";
        try {
            BufferedReader r = new BufferedReader(new FileReader(f));
            String s = r.readLine();
            while (s != null) {
                total += s + "\n";
                s = r.readLine();
            }
            r.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new ByteArrayInputStream(total.getBytes());

    }
}

Related Tutorials