📄 ficheirodeobjectos.java
字号:
import java.io.*;
public class FicheiroDeObjectos implements Serializable
{
private ObjectInputStream iS;
private ObjectOutputStream oS;
public void abreLeitura(String nomeDoFicheiro) {
try {
iS = new ObjectInputStream(new FileInputStream(nomeDoFicheiro));
} catch (Exception e) {
System.out.println ("N鉶 foi poss韛el abrir o ficheiro para leitura");
}
}
public void abreEscrita(String nomeDoFicheiro) {
try {
oS = new ObjectOutputStream(new FileOutputStream(nomeDoFicheiro));
} catch (Exception e) {
System.out.println ("N鉶 foi poss韛el abrir o ficheiro para escrita");
}
}
public Object leObjecto() {
try {
return iS.readObject();
} catch (ClassNotFoundException e) {
System.out.println ("O ficheiro n鉶 cont閙 objectos");
}
catch (Exception e1) {
System.out.println ("N鉶 foi poss韛el ler o ficheiro");
}
return iS;
}
public void escreveObjecto(Object o) {
try {
oS.writeObject(o);
} catch (Exception e) {
System.out.println ("N鉶 foi poss韛el abrir escrever no ficheiro");
}
}
public void fechaLeitura() {
try {
iS.close();
} catch (Exception e) {
System.out.println ("N鉶 foi poss韛el abrir fechar o ficheiro");
}
}
public void fechaEscrita() {
try {
oS.close();
} catch (Exception e) {
System.out.println ("N鉶 foi poss韛el abrir fechar o ficheiro");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -