dúvida em serialização

3 respostas
L

Colegas,

Estou precisando criar um metodo para serialização dos objetos de um container… Tentei fazer da seguinte forma:

public void serializar()

{

File file = new File("/bule/file/esboco.tmp");

if(!file.exists())

file.createNewFile();
FileOutputStream fileOut = new FileOutputStream(file);
  ObjectOutputStream objOut = new ObjectOutputStream(fileOut);
  objOut.writeObject("teste");

}

porém apresenta o seguinte erro:

Unreported exception java.io.IOException; must be caught or declared to be thrown

file.createNewFile();

Unreported exception java.io.IOException; must be caught or declared to be thrown

FileOutputStream fileOut = new FileOutputStream(file);


alguém sabe como resolver isto?
abs,

3 Respostas

Deh
public void serializar() throws IOException {

       //seu código aqui

}

era só ler: ->

Unreported exception java.io.IOException; must be caught or declared to be thrown
file.createNewFile();

java.io.IOException: deve ser capiturada(try/catch) ou declarada(throws)

=]

L

agora funcionou() a serialização.

Mas desculpe minha ignorância, mas agora estou tentando deserializar() da seguinte forma:

private void mtDeserializar() throws IOException

{

FileInputStream fileIn = new FileInputStream(file);

ObjectInputStream objIn = new ObjectInputStream(fileIn);

dados = (Hashtable) objIn.readObject();

}

e está dando o mesmo erro, agora neste metodo.
sabe como posso resolver isto:
abs.

U

Tive um problema parecido pode ser este seu Hashtable, pode ser
que na hora de deserealizar ele não encontre a classe,
dae junto com o throws IOException coloque o ClassNotFound.

Criado 1 de novembro de 2006
Ultima resposta 12 de nov. de 2006
Respostas 3
Participantes 3