将控制台的内容输出到文件中

public void writeToFile(){

try {
PrintWriter out = new PrintWriter(new FileWriter("d:\\myfile\\aaa.txt" ));

out.println("hello");
out.flush();
out.close();

} catch (IOException e) {
e.printStackTrace();
}
}

你可能感兴趣的:(控制台)