Ciao raga! Sto imparando il linguaggio Java e sono giunto a gli accessi ai file... ho fatto un source di questo programma, che deve semplicemente salvare l'oggetto su un file record
codice:
class Last{
public static void main(String args[]){
boolean x;
String nome;
float prezzo;
Libro l;
Scanner input = new Scanner(System.in);
System.out.println("Inserisci un nome del libro: ");
nome=input.nextLine();
do {
prezzo=input.nextFloat();
if (input.hasNextFloat) x=false;
else{
System.out.print("\0007");
x=true;
}
} while (x);
l=new Libro(nome, prezzo);
try {
FileOutputStream f = new FileOutputStream("libri.txt");
ObjectOutputStream fO = new ObjectOutputStream(f);
fO.writeObject(l);
fO.flush();
f.close();
}
catch (Exception e){
System.out.println("Tipo di eccezione: " + e.getMessage());
}
}
}
avendo la classe Libro scritta così:
codice:
class Libro{
public String nome;
public float prezzo;
public Libro (String nome, float prezzo){
this.nome=nome;
this.prezzo=prezzo;
}
}
e nel compilare la classe utilizzatrice col main che ho chiamato Last, da questi problemi:
codice:
C:\Users\Valerio\Desktop\Nuova cartella>javac Last.java
Last.java:7: error: cannot find symbol
Scanner input = new Scanner(System.in);
^
symbol: class Scanner
location: class Last
Last.java:7: error: cannot find symbol
Scanner input = new Scanner(System.in);
^
symbol: class Scanner
location: class Last
Last.java:20: error: cannot find symbol
FileOutputStream f = new FileOutputStream("libri.txt");
^
symbol: class FileOutputStream
location: class Last
Last.java:20: error: cannot find symbol
FileOutputStream f = new FileOutputStream("libri.txt");
^
symbol: class FileOutputStream
location: class Last
Last.java:21: error: cannot find symbol
ObjectOutputStream fO = new ObjectOutputStream(f);
^
symbol: class ObjectOutputStream
location: class Last
Last.java:21: error: cannot find symbol
ObjectOutputStream fO = new ObjectOutputStream(f);
^
symbol: class ObjectOutputStream
location: class Last
6 errors
C:\Users\Valerio\Desktop\Nuova cartella>
cosa può essere? Ho provato ad utilizzare degli IDE ma sono un po' complicati, non ho la stessa manualità di come l'avevo col C. Grazie in anticipo! =)