📄 simplecatch.java
字号:
import java.io.*;
/** A simple class that reads in its source code and displays it to the
console. It will print out error messages if an exception was thrown. */
public class SimpleCatch
{
/** Returns the contents of the file whose name is specified by the parameter, or a message
indicating why it couldn't be completed. */
public static String readFile(String file)
{
try
{
FileReader fr = new FileReader(file); // can throw a FileNotFoundException
BufferedReader br = new BufferedReader(fr);
String temp, result = new String();
while ((temp = br.readLine()) != null) // can throw an IOException
result += temp + "\n";
br.close();
return result;
}catch(FileNotFoundException e)
{
return "Can't find the source file to read.";
}catch(IOException e)
{
return "Sorry, a problem occured while reading the file.";
}
}
public static void main(String[] args)
{
System.out.println(readFile("SimpleCatch.java"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -