[英]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.