⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textfilescannerdemo.java

📁 java编程代码
💻 JAVA
字号:


import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class TextFileScannerDemo
{
    public static void main(String[] args)
    {
       System.out.println("I will read three numbers and a line");
       System.out.println("of text from the file morestuff.txt.");

       Scanner inputStream = null;

       try
       {
           inputStream =
              new Scanner(new FileInputStream("morestuff.txt"));
       }
       catch(FileNotFoundException e)
       {
           System.out.println("File morestuff.txt was not found");
           System.out.println("or could not be opened.");
           System.exit(0);
       }
           int n1 = inputStream.nextInt( );
           int n2 = inputStream.nextInt( );
           int n3 = inputStream.nextInt( );

           inputStream.nextLine(); //To go to the next line

           String line = inputStream.nextLine( );

           System.out.println("The three numbers read from the file are:");
           System.out.println(n1 + ", " + n2 + ", and " +  n3);

           System.out.println("The line read from the file is:");
           System.out.println(line);

           inputStream.close( );
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -