📄 eofdemo.java
字号:
import java.io.ObjectInputStream;
import java.io.FileInputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.FileNotFoundException;
public class EOFDemo
{
public static void main(String[] args)
{
try
{
ObjectInputStream inputStream =
new ObjectInputStream(new FileInputStream("numbers.dat"));
int number;
System.out.println("Reading numbers in numbers.dat");
try
{
while (true)
{
number = inputStream.readInt( );
System.out.println(number);
}
}
catch(EOFException e)
{
System.out.println("No more numbers in the file.");
}
inputStream.close( );
}
catch(FileNotFoundException e)
{
System.out.println("Cannot find file numbers.dat.");
}
catch(IOException e)
{
System.out.println("Problem with input from file numbers.dat.");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -