在方法的声明中使用throw子句
import java.io.IOException; public class Main { /** N o w J a v a . c o m 提供 **/ public static void main(String[] args) { char c = '\u0000'; try { System.out.print("Enter some text and then press Enter key:"); c = readChar(); System.out.println("The first character you entered is: " + c); } catch(IOException e) { System.out.println("Error occurred while reading input."); } } public static char readChar() throws IOException { char c = '\u0000'; /** * nowjava 提 供 **/