How to read a text file using scanner in Java?

Well.. Apparently the file does not exist or cannot be found. Try using a full path. You're probably reading from the wrong directory when you don't specify the path, unless a.

Txt is in your current working directory.

I would recommend loading the file as Resource and converting the input stream into string. This would give you the flexibility to load the file anywhere relative to the classpath.

If you are working in some IDE like Eclipse or NetBeans, you should have that a. Txt file in the root directory of your project. (and not in the file where your .

Class files are built or anywhere else) If not, you should specify the absolute path to that file. Edit: You would put the . Txt file in the same place with the .

Class(usually also the . Java file because you compile in the same folder) compiled files if you compile it by hand with javac. This is because it uses the relative path and the path tells the JVM the path where the executable file is located.

If you use some IDE, it will generate the compiled files for you using a Makefile or something similar for Windows and will consider it's default file structure, so he knows that the relative path begins from the root folder of the project.

But whats what my tutor told me, put the text file in the same folder as the java file – user764073 May 21 at 16:25 Edited my answer. Hope it helps. – iuliux May 21 at 19:19.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions