你如何从java中的USB拇指驱动器读取输入文件?

时间:2018-04-19 22:51:25

标签: java file-io usb-drive

Scanner reader = new Scanner(new File("INPUT.txt"));

这是我到目前为止所得到的java.io.FileNotFoundException。 有没有办法找到该文件。以下是我给出的指示,"教师将为您的组提供一个USB拇指驱动器,其根目录中包含一个名为INPUT.TXT的文本文件"

1 个答案:

答案 0 :(得分:0)

use Scanner reader = new Scanner(new File("E:\\INPUT.txt")

Right now its trying to find input.txt in the local directory, which is where the java project is.

You might not have it as the E drive, so make sure the drive letter is correct.

to use backslashes in java Strings you need two: \ - one to escape the other, as \ is used to escape characters sure as \n and \t