例如,我们的 file.getPath() 返回“Data\Cache\Character\images\1.png” 现在我想做的..是将字符串或其他路径或其他路径设置为:“Character\images\1.png”,因此从一开始就删除这两个第一个文件夹。谢谢。
最佳答案
您可以使用 Path
API 非常轻松地完成此操作:
final Path image = Paths.get("/", "Data", "Cache", "Character", "images", "1.png");
final Path base = Paths.get("/", "Data", "Cache");
System.out.println(image);
System.out.println(base);
final Path relativeImage = base.relativize(image);
System.out.println(relativeImage);
输出:
\\Data\Cache\Character\images\1.png
\\Data\Cache\
Character\images\1.png
关于java - 从 file.getpath() Java 中删除一些文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26688108/