Zach Nussbaum
Zach Nussbaum

Reputation: 11

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. 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? I am working in the Eclipse IDE and was curious as to why this occurred?

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. It worked later when I omitted 'src' when creating the new file

Upvotes: 0

Views: 1598

Answers (2)

Liyakat Shaikh
Liyakat Shaikh

Reputation: 115

provide full path e.g.

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

make sure you have correct file extension.

Upvotes: 0

Canan Durmus
Canan Durmus

Reputation: 80

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.

Upvotes: 3

Related Questions