iooperation.java
来自「飞机航班的查询系统」· Java 代码 · 共 50 行
JAVA
50 行
package planeInformation;
import java.io.*;
class IOOperation {
private File file = new File("C:\\info.txt");
public IOOperation() {
try {
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* write to file
*/
public void write(Plane[] s) {
try {
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream objOut = new ObjectOutputStream(fos);
objOut.writeObject(s);
objOut.close();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* read all student information from file
*/
public Plane[] getAllPlane() {
Plane ss[] = new Plane[100];
try {
if (file.length() > 0) {
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
ss = (Plane[]) ois.readObject();
ois.close();
fis.close();
}
} catch (Exception e) {
e.printStackTrace();
}
return ss;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?