gpt4 book ai didi

JAVA :How to Read file in Referenced Libraries

转载 作者:行者123 更新时间:2023-12-02 02:14:31 27 4
gpt4 key购买 nike

您好,我仅使用 FileReader 和 Bufferreader 读取文件,并且运行良好

fr = new FileReader("C:\\Users\\User\\Documents\\Bus_Station\\Bus station\\tripFile");          
br = new BufferedReader(fr);

但是我想读取将这些文件放在某个地方,所以我将它们放入引用库中,这样我就可以在没有路径的任何计算机上读取它们,但它不起作用:/

(File file = new File("tripFile.txt");
file.createNewFile();
fr = new FileReader(file););

有什么帮助吗?

最佳答案

您应该使用资源。

  URL fileURL = Resources.getResource("test.txt");
String text = Resources.toString(fileURL, Charsets.UTF_8);

如何添加资源文件夹

How do I add a resources folder to my Java project in Eclipse

adding resources in intellij for java project

How to create resource folder in Netbeans?

关于JAVA :How to Read file in Referenced Libraries,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49486861/

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