myfirstfilereadingapp.java

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

JAVA
29
字号
import java.io.*;

public class MyFirstFileReadingApp
{
	// Main method
	public static void main (String args[])
	{
		// Stream to read file
		FileInputStream fin;		

		try
		{
		    // Open an input stream
		    fin = new FileInputStream ("myfile.txt");

		    // Read a line of text
		    System.out.println( new DataInputStream(fin).readLine() );

		    // Close our input stream
		    fin.close();		
		}
		// Catches any error conditions
		catch (IOException e)
		{
			System.err.println ("Unable to read from file");
			System.exit(-1);
		}
	}	
}

⌨️ 快捷键说明

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