📜  将输出流打印到控制台 java 代码示例

📅  最后修改于: 2022-03-11 14:52:39.593000             🧑  作者: Mango

代码示例1
public static Writer createOutputWriter(String fileNm) {
    OutputStream os;
    if (fileNm.equals("") ) { // No file name provided, write to console
        os = System.out;
    }
    // File name provided, write to this file name
    else {
        try {
            os = new FileOutputStream(fileNm);
        }
        catch (FileNotFoundException fe) {
            System.out.println("File not found " + fe.toString());
        }
    }
    return new BufferedWriter(new OutputStreamWriter(os));
}