0

I'm just trying to do a simple text file read in java for my server. HOWEVER when I try to read the file I get an error saying that the file/directory cannot be found, the code I'm using to reference the file is as follows:

File levelOne = new File("lev1.txt");

The error is that it cannot find lev1.txt, which is within the src folder, and the class which is trying to access this, is in the default package. I have tried moving my text file into the default package but eclipse does not allow me to.

I have also tried moving both the class and txt file to a different package however this still gets file not found.

I'm really confused..

1
  • UPVOTE MY FRIEND! thanks a bunch... can't believe I didn't try that ! Commented Mar 28, 2012 at 20:15

1 Answer 1

2

You are assuming the file is in the current working directory. This has little or nothing to do with where the source is. It is usually the top of the module in most IDES, but it is wherever the program was run. (on the command line that could be anywhere)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.