ficheirodeobjectos.java

来自「Its a project that i create. The progra」· Java 代码 · 共 59 行

JAVA
59
字号
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 + =
减小字号Ctrl + -
显示快捷键?