こんにちは、オブジェクトのシリアル化を学んでいて、これを試しました
import java.io.*;
class Employee implements Serializable{
Employee(int temp_id,String temp_name)
{
id=temp_id;
name=temp_name;
}
int id;
String name;
}
public class SerialTest{
public static void main(String[] args)
{
Employee e1=new Employee(14,"John");
try{
FileOutputStream fileStream=new FileOutputStream("myserial.ser");
ObjectOutputStream os=new ObjectOutputStream(fileStream);
os.writeObject(e1);
}
catch(IOException ioex)
{
ioex.printStackTrace();
}
finally{
os.close();
}
}//main ends
}//class ends
プログラムは、呼び出しを入れる前に機能しました
os.close();
今、私はコンパイルしません。エラーが表示されます
SerialTest.java:29: cannot find symbol
symbol : variable os
location: class SerialTest
os.close();
^
ObjectOutPutStream を閉じようとする前に機能しました。シリアル化されたファイルの内容は以下のとおりです。
¬í^@^Esr^@^HEmployee^S<89>S§±<9b>éØ^B^@^BI^@^BidL^@^Dnamet^@^RLjava/lang/String;xp^@^@ ^@^Nt^@^GSainath ~
どこが間違っているのか理解できません。助けてください!