Tag: 相对

使用Path类在Java中的两个路径之间创建路径

这个 oracle java教程中的这个句子究竟是什么意思: 如果只有一个路径包含根元素,则不能构造相对路径。 如果两个路径都包含根元素,则构造相对路径的能力取决于系统。 对于“系统依赖”,它们仅表示如果一个元素包含一个根,它只能在已编写的平台特定语法中工作吗? 我想这是他们唯一的意思。 还有其他方法可以阅读吗? 例如 : public class AnotherOnePathTheDust { public static void main (String []args) { Path p1 = Paths.get(“home”); Path p3 = Paths.get(“home/sally/bar”); //with “/home/sally/bar” i would get an exception. // Result is sally/bar Path p1_to_p3 = p1.relativize(p3); // Result is ../.. Path p3_to_p1 = p3.relativize(p1); System.out.println(p3_to_p1); } } […]

从/ src / main / resources /读取文件

您好我正在尝试执行Web应用程序并遇到问题:我不知道如何使用保存在资源文件夹中的Java打开文本文件: String relativeWebPath =”/src/main/resources/words.txt”; //Import der des Textdoumentes String absoluteDiskPath = getServletContext().getRealPath(relativeWebPath); File f = new File(absoluteDiskPath); (文件words.txt) 正如您在图像上看到的那样,我正在尝试访问words.txt,但它无法正常工作。 有任何想法吗?

如何在java中定义相对路径(Windows)

这是我的项目的结构: 我需要读取MyClass.java config.properties 。 我尝试使用相对路径执行此操作,如下所示: // Code called from MyClass.java File f1 = new File(“..\\..\\..\\config.properties”); String path = f1.getPath(); prop.load(new FileInputStream(path)); 这给了我以下错误: ..\..\..\config.properties (The system cannot find the file specified) 如何在java中定义相对路径? 我正在使用jdk 1.6并在Windows上工作。