📄 5-5
字号:
import java.io.*;
class sum{
public static void main(String args[]) //方法main()没有抛出异常
{
DataInputStream fis=null;
try //try体可能有抛出的异常或程序错
{
fis=new DataInputStream(new FileInputStream("myfile.txt"));//建立读入"myfile.txt"文件的输
//入流
String stra=fis.readln(); //读入一个字符串,.readln()抛出异常
int a=Integer.parseInt(stra);//把该字符串转化为整数
String strb=fis.readln();//读入一个字符串,.readln()抛出异常
int b =Integer.parseInt(strb); //把该字符串转化为整数
int c=a+b;
System.out.println(c.toString());
//输出c
fis.close();
}
catch(FileNotFoundException e) //
{
System.out.println(e.toString());
}
catch(IOException e)
{
System.out.println(e.toString());
fis.close();
}
catch(NumberFormatException e)
{
System.out.println(e.toString());
fis.close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -