我的程序正在创建文件,我需要将它们放在特定的文件夹中。不确定这个过程。感谢
String path = "C:\\Users\\Blah\\Desktop\\blahblah\\FOLDER";
File bfFolder = new File (path);
bfFolder.mkdir();
for (int a = 0; a < 20; a++) {
try (DataOutputStream dataO = new DataOutputStream(new FileOutputStream("file" + " a"))) {
答案 0 :(得分:0)
您可以将File
传递给new FileOutputStream()
。要在您创建的目录中创建新的File
,请将父目录和文件名传递给构造函数:
// This will refer to C:\Users\Blah\Desktop\blahblah\FOLDER\name.txt
File myFile = new File(bfFolder, "name.txt");
try(FileOutputStream fStream = new FileOutputStream(myFile);
DataOutputStream data0 = new DataOutputStream(fStream)) {
答案 1 :(得分:0)
查看Files.copy(),这是一种快速完成所需操作的方法。