如何将文件添加到我的文件夹? java
How do I add files to my folder? java
我的程序正在创建文件,我需要将它们放在特定的文件夹中。不确定过程。谢谢
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"))) {
您可以将 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)) {
查看 Files.copy(),这是一种快速完成所需操作的方法。
我的程序正在创建文件,我需要将它们放在特定的文件夹中。不确定过程。谢谢
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"))) {
您可以将 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)) {
查看 Files.copy(),这是一种快速完成所需操作的方法。