Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 逐行阅读指令_Java_File Io_Java.util.scanner - Fatal编程技术网

Java 逐行阅读指令

Java 逐行阅读指令,java,file-io,java.util.scanner,Java,File Io,Java.util.scanner,我在文本文件中有一组说明: LoadA 0 LoadB 1 Add Store 0 LoadA 2 etc... 我知道我可以使用Scanner和hasNextLine,但不知道如何实现这一点,也不知道如何阅读和理解说明 Scanner inFile = null; try { // Create a scanner to read the file, file name is parameter inFile = new Scanner (n

我在文本文件中有一组说明:

LoadA 0

LoadB 1

Add

Store 0

LoadA 2

etc...
我知道我可以使用Scanner和hasNextLine,但不知道如何实现这一点,也不知道如何阅读和理解说明

Scanner inFile = null;
try 
    {
       // Create a scanner to read the file, file name is parameter
        inFile = new Scanner (new File("whatever.txt"));
        } 
        catch (FileNotFoundException e) 
        {
        System.out.println ("File not found!");
        // Stop program if no file found
        System.exit (0);
        }
那么


如果这还不能解决问题,我建议大家看一看

,因为上面的人希望你自己做这件事。我会回答这个问题,因为我记得学习是多么困难。只要你从中学习,而不是仅仅复制它们,这应该是有用的

Scanner sc = new Scanner(System.in);   //read from the System.in
while (sc.hasNextLine()) { //this will continue to itterate until it runs out
     String[] x = sc.nextLine().split(" ");
     //this takes your input and puts it into a string array where there is a 
     //space e.g. ["LoadA", "0"]
}

我希望这有帮助。你仍然需要解决这个问题。您现在可以获取内容了。祝你好运。

所以这里不是让人们做你的家庭作业的地方,
自己学习,解决它,然后如果你面临任何问题,这个社会总是会帮助你,试着先阅读教程!!尼拉杰·詹,我一直在努力解决这个问题。我不知道如何实施它。我需要帮助完成这一部分,大约是整个作业的1/15。谢谢你的帮助。非常感谢!!很有帮助
Scanner sc = new Scanner(System.in);   //read from the System.in
while (sc.hasNextLine()) { //this will continue to itterate until it runs out
     String[] x = sc.nextLine().split(" ");
     //this takes your input and puts it into a string array where there is a 
     //space e.g. ["LoadA", "0"]
}