gpt4 book ai didi

java - Java中如何指定文件路径?

转载 作者:行者123 更新时间:2023-12-01 22:13:04 25 4
gpt4 key购买 nike

如何在Java中添加文件扫描器的路径?我使用 Ubuntu 和 Intellij。我想我一切都好,但还是不行:(

代码:

 File file = new File("/abc/file.txt");

错误:

java.io.FileNotFoundException: /abc/file.txt (No such file or directory)

inte

最佳答案

您的 abc 文件夹位于 src 下,并且您使用的是带有前导 / 的绝对路径,该路径将其声明为文件的根目录系统。

将文件夹移动到项目根文件夹,引用如下

File file = new File("abc/file.txt");

关于java - Java中如何指定文件路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58643157/

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