创建文件,路径可以是绝对路径,也可以是相对路径:
File file= new File("路径名.后缀名");
重定向输入流:
PrintStream ps = new PrintStream("路径名.后缀名");
System.setOut(ps);
//之后所有的输出都是写入你重定向的文件中
重定向输出流:
InputStream is = new FileInputStream("./log.txt");
System.setIn(is);
或:
Writer out = new FileWriter(xxx); //xxx 为文件名
out.write(xxx);//xxx为内容,一般是字符串
//主函数一般这么写:
public static void main(String[] args) throws IOException {
}
//记得out.close();