📄 testprintwriters.java
字号:
// TestPrintWriters.java
import java.io.*;
public class TestPrintWriters
{
// Main method: args[0] is the output file
public static void main(String[] args)
{
// 声明打印流
PrintWriter pw = null;
// 检查命令参数是否存在
if (args.length != 1)
{
System.out.println("输入命令参数文件");
System.exit(0);
}
File tempFile = new File(args[0]);
if (tempFile.exists())
{
System.out.println("The file " + args[0] +
" already exists, delete it, rerun the program");
System.exit(0);
}
// 写数据
try
{
pw = new PrintWriter(new FileOutputStream(tempFile), true);
for (int i=0; i<10; i++)
pw.print(" "+(int)(Math.random()*1000));
}
catch (IOException ex)
{
System.out.println(ex.getMessage());
}
finally
{
// 关闭文件
if (pw != null) pw.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -