我想在java Eclipse中的控制檯中編寫幾行命令,然後將它們保存爲.txt文件。 比如我有如何將控制檯輸入的行保存爲.txt文件?
做到這一點
不這樣做
在我的控制檯,我想有同樣的事情爲.txt file.Now我可以將其轉換爲一個文件,但不一個.txt文件和不可讀的形狀。 有幫助嗎?我一直工作在這3天,現在:))
我認爲這是最接近我能得到
FileInputStream fileInputStream=null;
File file = new File("C:\\Users\\Administrator\\Desktop\\a.txt");
byte[] bFile = new byte[(int) file.length()];
try {
//convert file into array of bytes
fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
//convert array of bytes into file
FileOutputStream fileOuputStream =
new FileOutputStream("C:\\Users\\Administrator\\Desktop\\a.txt");
fileOuputStream.write(bFile);
fileOuputStream.close();
System.out.println("Done");
}catch(Exception e){
e.printStackTrace();
}
忘了PrintWriter:D謝謝你問題解決了 – user2044260