[英]Get normalized path for windows location in Java
I have a requirement where I have a path as C:\..\bar
for this the file bar gets created in the C drive when I use this path in SQL server.我有一个要求,我的路径为C:\..\bar
当我在 Z9778840A0100CB30C9822876741B0B5A 服务器中使用此路径时,文件栏会在 C 驱动器中创建。 Now on using Apache's FilenameUtils, The normalize
method returns null as also documented.现在在使用 Apache 的 FilenameUtils 时, normalize
方法返回 null,如文档所述。
- C:\..\bar --> null C:\..\bar --> null
But I want但我想要
C:\bar for C:\..\bar C:\bar 对于 C:\..\bar
Is there any way in Java to get C:\bar for C:\..\bar I know that ..
would mean parent directory but SQL server still creates file the C drive. Is there any way in Java to get C:\bar for C:\..\bar I know that ..
would mean parent directory but SQL server still creates file the C drive.
You can use getCanonicalFile
.您可以使用getCanonicalFile
。
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
File file = new File("C:\\..\\bar");
System.out.println(file.getCanonicalFile());
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.