reader = new CSVReader(new FileReader("file.txt"));
The file is placed in the same directory as the java class. Anyhow I get FileNotFoundException.
What is wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Relative paths are relative to the current working directory. In your code sample, if
file.txtisn’t in your current directory, it won’t be found.Be wary of using relative paths in your code. That’s because it’s impossible to tell at compile time what the current working directory will be when your code is run.
If the file is part of your deployment, store it on the classpath and access it via
ClassLoader.getResourceAsStream(), if it’s truly external data that the user can change, put the file name in a configuration of some sort.