简体   繁体   中英

Scanner and reading from a file

i have to parse a text file using the Scanner, I know how to use the delimiter to parse the text, but i don't know how to make my program accept a file.txt as an input and then to start chopping it off. Can anyone help me with this? Tnx in advance!

Look at the Scanner API. It has a constructor that will accept a File parameter. Use it.

String fileName = "fileName.txt";
File file = new File(fileName);
Scanner fileScanner = new Scanner(file);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM