📄 5-5.txt
字号:
import java.io.*;
class sum
{
public static void main(String args[])
{
DatalnputStream fis=null;
try
{
fis=new DataInputStream(new FileInputStream("myfile.txt"));
//建立读入"myfile.txt"文件的输入流
String stra=fis.readln();
//读入一个字符串
int a=Integer.parseInt(stra);
//把该字符串转化为整数
String strb=fis.readln();
int b=Integer.parseInt(strb);
int c=a+b;
System.out.println(c.toString());
//输出c
}
catch(FileNotFoundexception e)
{
System.out.printIn(e.toString());
}
catch(IOException e)
{
System.out.println(e.toString());
}
catch(NumberFormatException e)
{
System.out.println(e.toString());
}
finally
{
if(fis= =null)
{
System.out.println("DateInputStream not open!")
//输入流没有打开
}
else
{
fis.close();
关闭输入流
System.out.println("Close DalaInStream!");
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -