textfileinputdemo.java

来自「java编程代码」· Java 代码 · 共 39 行

JAVA
39
字号

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.io.IOException;

public class TextFileInputDemo
{
    public static void main(String[] args)
    {
       try
       {
           BufferedReader inputStream = 
              new BufferedReader(new FileReader("morestuff2.txt"));

           String line = inputStream.readLine( );
           System.out.println(
                            "The first line read from the file is:");
           System.out.println(line);
        
           line = inputStream.readLine( );
           System.out.println(
                           "The second line read from the file is:");
           System.out.println(line); 
           inputStream.close( );
       }
       catch(FileNotFoundException e)
       {
           System.out.println("File morestuff2.txt was not found");
           System.out.println("or could not be opened.");
       }
       catch(IOException e)
       {
           System.out.println("Error reading from morestuff2.txt.");
       }
    }
}

⌨️ 快捷键说明

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