fileread.java

来自「Reads/writes text as a character stream,」· Java 代码 · 共 27 行

JAVA
27
字号
import java.io.*;

class FileRead{
   public static void main(String args[])
	{
      try{
		// Open the file that is the first 
		// command line parameter
		FileInputStream fstream = new FileInputStream("textfile.txt");
		// Get the object of DataInputStream
		DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
		String strLine;
		//Read File Line By Line
		while ((strLine = br.readLine()) != null) 	{
			// Print the content on the console
			System.out.println (strLine);
		}
		//Close the input stream
		in.close();
		}catch (Exception e){//Catch exception if any
			System.err.println("Error: " + e.getMessage());
		}
	}
}

⌨️ 快捷键说明

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