Ciao a tutti gli utenti del forum!!!
Ho un piccolo problema con un mio programmino java
ecco il codice (scritto da me) che mi da problemi:
//Carica un database serializzato da un file binario.
public void carica(String nomeFile) {
FileInputStream fis = new FileInputStream(nomeFile);
ObjectInputStream ois = new ObjectInputStream(fis);
DatabaseAuto da = (DatabaseAuto)ois.readObject(); //DatabaseAuto è la classe in cui si trova questo metodo
ois.close();
fis.close();
}
Il main richiama questo metodo in questo modo:
dbAuto1.carica("databaseAuto.bin");
--------------------------------------
ERRORI:
test.java:153: unreported exception java.io.FileNotFoundException; must be caugh
t or declared to be thrown
FileInputStream fis = new FileInputStream(nomeFile);
^
test.java:154: unreported exception java.io.IOException; must be caught or decla
red to be thrown
ObjectInputStream ois = new ObjectInputStream(fis);
^
test.java:155: unreported exception java.io.IOException; must be caught or decla
red to be thrown
DatabaseAuto da = (DatabaseAuto)ois.readObject();
^
test.java:156: unreported exception java.io.IOException; must be caught or decla
red to be thrown
ois.close();
^
test.java:157: unreported exception java.io.IOException; must be caught or decla
red to be thrown
fis.close();
^
test.java:255: unreported exception java.io.FileNotFoundException; must be caugh
t or declared to be thrown
FileOutputStream fos = new FileOutputStream(nomeFile);
^
test.java:256: unreported exception java.io.IOException; must be caught or decla
red to be thrown
ObjectOutputStream oos = new ObjectOutputStream(fos);
^
test.java:257: unreported exception java.io.IOException; must be caught or decla
red to be thrown
oos.writeObject(sA);
^
test.java:258: unreported exception java.io.IOException; must be caught or decla
red to be thrown
oos.writeObject(sT);
^
test.java:259: unreported exception java.io.IOException; must be caught or decla
red to be thrown
oos.flush();
^
test.java:260: unreported exception java.io.IOException; must be caught or decla
red to be thrown
oos.close();
^
test.java:261: unreported exception java.io.IOException; must be caught or decla
red to be thrown
fos.close();
^
12 errors
---------------------------------
io ho pensato di dichiarare il metodo:
public void carica(String nomeFile) throws IOException, ClassNotFoundException {...}
ma così facendo mi da errore nella chiamata del metodo nel blocco main.
E non posso modificare il main.
Ovviamente ho importato java.io.*; (import java.io.*
FileInputStream lo potete trovare all'indirizzo http://java.sun.com/j2se/1.5.0/docs/api/
ObjectInputStream lo potete trovare all'indirizzo http://java.sun.com/j2se/1.5.0/docs/api/
Spero che qualcuno mi posso aiutare!!! in anticipo: GRAZIE!!!