Output message to a file or stdout
来源:互联网 发布:淘宝hd版怎样改电脑版 编辑:程序博客网 时间:2024/05/20 22:31
Use case:
When an output file is defined, message will be printed to file, otherwise message will be printed to stdout.
import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.OutputStream;import java.io.PrintStream;public class TestMain { public static void main(String[] args) { TestMain m = new TestMain(); PrintStream ps = m.getPrintStream("/tmp/a.txt"); ps.print("Hello World!"); } /** * Print message to file identified by filename, * or stdout if filename is not provided. * * @param filename * @return */ @SuppressWarnings("resource") public PrintStream getPrintStream (String filename) { OutputStream os = null; try { os = new FileOutputStream(filename); } catch (FileNotFoundException e1) { os = System.out; } PrintStream ps = new PrintStream(os); return ps; }}
0 0
- Output message to a file or stdout
- Express Morgan not writing logs to file or STDOUT
- MetaException(message:file:/user/hive/warehouse/xxxx is not a directory or unable to create one)
- write error message to a file
- How To Redirect stderr To stdout ( redirect stderr to a File )
- compiler error output to a file named err
- program output redirect to a file named t
- [Cexpert-004] How to output strings to stdout/stderr directly?
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64
- How to Output a List of Files to a File and Sort Them in Linux
- Redirect all output to file
- FILE *stdout 和 STDOUT
- Define and output a file
- C++ 之父给C程序员的建议
- Ajax跨域解决方案
- 11.12
- User-Agent头部文件获取方法
- jquery中的for循环与each循环
- Output message to a file or stdout
- 机器学习中的范数规则化之(一)L0、L1与L2范数
- Matlab 图像处理 增加图像亮度(曝光度)算法
- HBASE原理笔记
- 求数组排序后相邻两个数的最大差值
- Android Adapter接口及实现类之ArrayAdapter、SimpleAdapter和BaseAdapter的简单介绍及运用
- Oracle 11g安装图文教程
- Android——线程通信 HandlerThread
- eclipse中报 无法加载主类 问题 但在java命令能编译过