我正在阅读oracle,以了解如何使用java.nio.file功能中的路径而不是java.io.File功能创建文件,这是示例代码:
Path file = ...;
try {
// Create the empty file with default permissions, etc.
Files.createFile(file);
} catch (FileAlreadyExistsException x) {
System.err.format("file named %s" +
" already exists%n", file);
} catch (IOException x) {
// Some other sort of failure, such as permissions.
System.err.format("createFile error: %s%n", x);
}但是什么在.;空间?我应该在那里打什么?
发布于 2018-04-10 05:44:56
用于保存文件的
eg
Path path = Paths.get("src/main/resources/question.txt");Path对象是系统上到文件或目录的路径的分层表示形式。java.nio.file.Path接口是使用NIO2API的主要入口点。
创建Path对象的最简单方法是使用java.nio.files.Paths工厂类。该类具有一个静态get()方法,该方法可用于获取对文件或目录的引用。该方法接受字符串或字符串序列(它将加入这些字符串以形成路径)作为参数。像文件一样,java.nio.file.Path可以指文件系统中的绝对路径或相对路径。
https://stackoverflow.com/questions/49745848
复制相似问题