简体   繁体   English

将文件存储在驱动器目录中

[英]Store File in Directory of Drive

 {
      headFile = File.createTempFile("HMh", ".tmp");
      headCreated = true;
      dataFile = File.createTempFile("HMd",".tmp");
      dataCreated = true;
      headOut = new DataOutputStream((new BufferedOutputStream(new FileOutputStream(headFile))));
      dataOut = new DataOutputStream((new BufferedOutputStream(new FileOutputStream(dataFile))));
    }

I have this code where headOut is being referenced and writing temp File to headFile, I want to replace the temporary File with the File to be stored in Directory in Windows D Drive so as too see the Files being stored physically . 我在引用headOut的地方有此代码,并将temp File写入headFile,我想用要存储在Windows D Drive中Directory中的文件替换临时File,这样也可以看到物理存储的文件。 Please help with the code . 请帮助代码。 As it creates multiple Temp File please let know to append the File name with the Date Time value so as it doesent overide existing Temp Files . 由于它会创建多个临时文件,因此请在文件名后加上“日期时间”值,以使其覆盖现有的临时文件。

long l  = new Date().getTime();

File.createTempFile("HMh"+l, ".tmp") It will append timestamps to your file. File.createTempFile("HMh"+l, ".tmp")它将时间戳添加到您的文件。

Write file on drive. 将文件写入驱动器。

File file = new File("C:\\filename.txt");
// creates the file
file.createNewFile();
// creates a FileWriter Object
FileWriter writer = new FileWriter(file); 
// Writes the content to the file
writer.write("This\n is\n an\n example\n");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将目录存储为File对象还是String? - Store a directory as a File object or a String? 如何在不指定驱动器的情况下在“ src”(源)目录中创建文件 - How to create file in 'src' (source) directory without specifing the drive Java 使用哪种协议将文件存储在共享驱动器上? - Which Protocol Java is using to store file at shared drive? 如何将从S3下载的文件对象存储到本地目录 - How to store a downloaded file object from S3 to a local directory 在特定目录中查找文件名并存储在数组列表中的代码 - A code that looks for a file name in a specific directory and store in in the array list 如何使用Java获取所有LDAP目录用户并将其存储到文件中 - how to get all LDAP directory user and store it to a file using Java 如何将H2数据库文件存储到项目目录中 - How to store H2 database file into project directory 如何使用Java将文件列表从控制台存储到目录? - How to store file list from console to directory using java? Google云端硬盘-java.io.FileNotFoundException:document.txt(无此类文件或目录) - Google drive - java.io.FileNotFoundException: document.txt (No such file or directory) MS DOS命令或Java代码复制文件是否将目录从一个驱动器复制到多个驱动器? - MS DOS command or Java code to Copy a file are directory from one drive to Multiple Drives?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM