simplethrows.java

来自「国外的数据结构与算法分析用书」· Java 代码 · 共 24 行

JAVA
24
字号
import java.io.*;

/**	A simple program that reads in its own source code and displays it to the
	console.  The program will crash if it encounters any errors. */
public class SimpleThrows
{
	/**	 Returns the contents of the file pointed to by the parameter. */
	public static String readFile(String file) throws IOException
	{
		FileReader fr = new FileReader(file); // can throw an exception
		BufferedReader br = new BufferedReader(fr);
		String temp, result = new String();
		while ((temp = br.readLine()) != null) // can throw an exception
			result += temp + "\n";
		br.close();
		return result; // return file contents
	}

	public static void main(String[] args) throws IOException
	{
		System.out.println(readFile("SimpleThrows.java"));
	}
}

⌨️ 快捷键说明

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