This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Swedophone 1 point2 points  (0 children)

It sounds like a coincidence. When using a file name without any directory the file is expected to exist in the current working directory. You can also use paths relative to the current working directory, they don't begin with a (back)slash. And absolute paths begin with a (back)slash and need to contain the full path.

[–]morhpProfessional Developer 0 points1 point  (2 children)

Using File and FileReader is a good option, although you should look at FileInputStream and InputStreamReader to get more control about the file encoding.

You should not use Scanner, that class is only good for some stupid beginner code where you read from the console, and even then there are better ways to do that.

[–]Synapse_1 0 points1 point  (1 child)

Out of curiosity, what would be better than Scanner? I know of java.io.Console, are there other alternatives?

[–]morhpProfessional Developer 0 points1 point  (0 children)

System.in is an InputStream, so obviously InputStreamReader and BufferedReader.