【发布时间】:2020-11-27 12:00:35
【问题描述】:
我创建了一个空的 File 并存储从 jar 中提取的值/内容。 jar 在 linux 上运行。
String filename ="base_script";
File targetFile = new File( filename + ".sh");
String pathStr=null;
//empty file
targetFile.createNewFile();
if(targetFile.exists()) {
InputStream link = (getClass().getResourceAsStream(this.userScriptPath));
Files.copy(link,
targetFile.getAbsoluteFile().toPath(),
java.nio.file.StandardCopyOption.REPLACE_EXISTING);
pathStr = targetFile.getAbsolutePath();
}
这是文件路径./base_script.sh
这是文件绝对路径apps/MyApps/./base_script.sh
我的问题是为什么在绝对路径上有一个额外的./?
【问题讨论】:
-
相对路径首先解析为 cwd ./ ; relative 的绝对路径前缀,因此包括 ./
-
我在运行它时收到了
no such file or directoryerror。如果没有./就可以了