简体   繁体   English

文件在src中但不是默认软件包? Java的

[英]File in src but not default package? Java

This may be very abstractly written, as I'm not sure of a good other way. 这可能是非常抽象的,因为我不确定其他方法。 In Java, I wrote something that creates a file and saves it in that folder. 在Java中,我写了一些东西来创建文件并将其保存在该文件夹中。 I then have another class/object that takes those files and uses those files to do some calculations. 然后,我还有另一个类/对象接收这些文件并使用这些文件进行一些计算。 Why do I get thrown a FileNotFoundException when those files are saved in the default package of the src but not when they are saved outside the default package? 为什么将这些文件保存在src的默认程序包中而不将它们保存在默认程序包之外时却引发FileNotFoundException I am working in the Eclipse IDE and was curious as to why this occurred? 我正在Eclipse IDE中工作,并对为什么会发生这种情况感到好奇?

EDIT: I tried to create a file File temp = new File("src/random.txt") and this is where I was running into my problem and getting the errors thrown. 编辑:我试图创建一个文件File temp = new File(“ src / random.txt”),这是我遇到问题并引发错误的地方。 It worked later when I omitted 'src' when creating the new file 后来当我在创建新文件时省略“ src”时,它起作用了

As far as I can guess from your description above, you are not providing path for the files, just use file names? 据我从上面的描述可以猜到的,您没有提供文件的路径,仅使用文件名? That's why your application is looking for the files where it runs. 这就是为什么您的应用程序正在寻找运行文件的原因。

provide full path eg 提供完整的路径,例如

String csvFile = "D:\\Documents\\ex\\myFile.csv";
FileReader fileReader = new FileReader(csvFile);

make sure you have correct file extension. 确保您具有正确的文件扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM