📄 iooperation.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -