print outputstream to console java

Solutions on MaxInterview for print outputstream to console java by the best coders in the world

showing results for - "print outputstream to console java"
Juan Manuel
07 May 2016
1public static Writer createOutputWriter(String fileNm) {
2    OutputStream os;
3    if (fileNm.equals("") ) { // No file name provided, write to console
4        os = System.out;
5    }
6    // File name provided, write to this file name
7    else {
8        try {
9            os = new FileOutputStream(fileNm);
10        }
11        catch (FileNotFoundException fe) {
12            System.out.println("File not found " + fe.toString());
13        }
14    }
15    return new BufferedWriter(new OutputStreamWriter(os));
16}
17