我想在java中创建一个不存在的.dat文件.我不知道如何手动创建它.文件f =新文件(文件); 是用于文件的代码,但究竟是不存在的文件的代码是什么.换句话说,创建一个新文件.
类似的语句File f = new File(file);
不会在磁盘上创建文件.类java.io.File
仅表示文件路径,而不是磁盘上的实际文件.
要创建新文件,请打开一个新文件,FileOutputStream
然后可以使用该文件将数据写入文件.
OutputStream out = new FileOutputStream("C:\\Temp\\filename.dat");
try {
// Write data to 'out'
} finally {
// Make sure to close the file when done
out.close();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
20514 次 |
最近记录: |