什么 java 复制文件的方法可以处理波浪号 (~) 的使用,特别是在 Linux 中,而不必用 System.getProperty("user.home")
手动替换波浪号或"/home/"
?
例如:我想复制~/this/path/file.txt
到~usera/other/path/filea.txt
我试过使用 Files.copy(Path a, Path b)
, FileUtils.copyFile( File a, File b)
, FileInputStream
& FileOutputStream
最佳答案
外壳处理波浪线扩展。 Java 中没有方法可以做到这一点。你可以使用
System.getProperty("user.home")
这将获取当前用户的主目录(在 Linux 中为 ~
)。
关于java - 什么复制文件的方法可以处理波浪号? (~),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32742449/