gpt4 book ai didi

java - Jar 访问外部文件

转载 作者:太空宇宙 更新时间:2023-11-04 12:33:39 29 4
gpt4 key购买 nike

我有一个结构如下的文件夹:

我的文件夹:

  • 文件1.xml
  • 文件2.xml
  • 项目.jar

但是如果在类里面我使用:

File f = new File("file1.xml");

我收到错误,因为找不到该文件。为什么?

最佳答案

您应该在代码中使用相对路径。

示例:File f = new File("./file1.xml");

关于java - Jar 访问外部文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37570394/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com