简体   繁体   English

扫描仪和文件读取

[英]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. 我必须使用扫描仪来解析文本文件,我知道如何使用定界符来解析文本,但是我不知道如何使程序接受file.txt作为输入,然后开始将其切掉。 Can anyone help me with this? 谁能帮我这个? Tnx in advance! 提前Tnx!

Look at the Scanner API. 查看Scanner API。 It has a constructor that will accept a File parameter. 它具有一个接受File参数的构造函数。 Use it. 用它。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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