Java - 如何将文件写入指定目录
2022-09-01 04:59:34
我想将文件结果写入.txt到计算机上的特定目录(确切地说是Z:\results)。如何为 BufferedWriter/FileWriter 指定目录?
目前,它成功地将文件写入我的源代码所在的目录。谢谢
public void writefile(){
try{
Writer output = null;
File file = new File("results.txt");
output = new BufferedWriter(new FileWriter(file));
for(int i=0; i<100; i++){
//CODE TO FETCH RESULTS AND WRITE FILE
}
output.close();
System.out.println("File has been written");
}catch(Exception e){
System.out.println("Could not create file");
}
}