8 Replies Latest reply: Apr 1, 2010 9:28 AM by 843790 RSS

    Serialization cause to unreadable characters!!!

    843790
      I wrote a bean called 'Word' including a property of phonetic symbol like /ræt/ etc. When I serialize it in disk and then deserialize it ,I found these phonetic symbol become unreadable characters.
      Following is code, short:
      /*
       * To change this template, choose Tools | Templates
       * and open the template in the editor.
       */
      package check;
      
      import java.io.*;
      public class Check {
      
          public static void main(String[] args) throws Exception {
      
              MyWord word=new MyWord(1,"rat"," /ræt/");
      
              String path = "d:/words/words.data";
              ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(path));
              oos.writeObject(word);
              oos.close();
      
              ObjectInputStream ois = new ObjectInputStream( new FileInputStream(path));
              MyWord w=(MyWord)ois.readObject();
              ois.close();
              System.out.println(w.getSymbol());
          }
      }
      
      class MyWord implements Serializable{
          private Integer id;
          private String spell;
          private  String symbol;//phonetic symbol
      
          MyWord(Integer id, String spell, String symbol) {
              this.id = id;
              this.spell = spell;
              this.symbol = symbol;
          }
      
          public Integer getId() {
              return id;
          }
      
          public void setId(Integer id) {
              this.id = id;
          }
      
          public String getSpell() {
              return spell;
          }
      
          public void setSpell(String spell) {
              this.spell = spell;
          }
      
          public String getSymbol() {
              return symbol;
          }
      
          public void setSymbol(String symbol) {
              this.symbol = symbol;
          }
      }
      thanks