Document中是不是有不能序列化的对象呀
参照http://www.csdn.net/expert/topic/637/637704.xml?temp=.5445368
好象是没问题

解决方案 »

  1.   

    下面这个例子就序列化包含日文的对象,没问题的(不好意思,我的系统是日文的)
    我感觉应该是你的Document的中包含有没有继承serialable接口的对象
    如果不是的话,你可以把代码贴出来,我帮你看一下
    import java.io.*;
    import javax.swing.*;
    public class test{
        JTextField tf = new JTextField("核");
        public static void main(String [] arg){
            test test1 = new test();
            test1.invoke();
        }
        public void invoke(){
            try{
                ObjectOutputStream os=new ObjectOutputStream(new FileOutputStream("1.dat"));
                os.writeObject(tf);
                os.flush();
                os.close();
                System.out.println("Before Serial" + tf.getText());
                System.out.println("****************************");
                ObjectInputStream in= new ObjectInputStream(new FileInputStream("1.dat"));
                JTextField tfnew = (JTextField)in.readObject();
                in.close();
                System.out.println("After Serial" + tfnew.getText());
            }catch(Exception e){}
        }
    }
      

  2.   

    //读出文件中对象的类:
    class OpenAction extends AbstractAction { OpenAction() {
        super(openAction);
    }        public void actionPerformed(ActionEvent e) {
        Frame frame = getFrame();
        if (fileDialog == null) {
    fileDialog = new FileDialog(frame);
        }
        fileDialog.setMode(FileDialog.LOAD);
        fileDialog.show();     String file = fileDialog.getFile();
        if (file == null) {
    return;
        }
        String directory = fileDialog.getDirectory();
        File f = new File(directory, file);
        if (f.exists()) {
    try {
        FileInputStream fin = new FileInputStream(f);
        ObjectInputStream istrm = new ObjectInputStream(fin);
        Document doc = (Document) istrm.readObject();
        if(getEditor().getDocument() != null)
    getEditor().getDocument().removeUndoableEditListener
                (undoHandler);
        getEditor().setDocument(doc);
        doc.addUndoableEditListener(undoHandler);
        resetUndoManager();
        frame.setTitle(file);
        validate();
    } catch (IOException io) {
        // should put in status panel
        System.err.println("IOException: " + io.getMessage());
    } catch (ClassNotFoundException cnf) {
        // should put in status panel
    System.out.println("Read Errors!");
        System.err.println("Class not found: " + cnf.getMessage());
    }
        } else {
    // should put in status panel
    System.err.println("No such file: " + f);
        }
    }
        }//将对象写入文件的类:
    class SaveAction extends AbstractAction { SaveAction() {
        super(saveAction);
    }        public void actionPerformed(ActionEvent e) {
        Frame frame = getFrame();
        if (fileDialog == null) {
    fileDialog = new FileDialog(frame);
        }
        fileDialog.setMode(FileDialog.SAVE);
        fileDialog.show();
        String file = fileDialog.getFile();
        if (file == null) {
    return;
        }
        String directory = fileDialog.getDirectory();
        File f = new File(directory, file);
        try {
    FileOutputStream fstrm = new FileOutputStream(f);
    ObjectOutput ostrm = new ObjectOutputStream(fstrm);
    //ByteArrayOutputStream bastrm = new ByteArrayOutputStream()
    ostrm.writeObject(getEditor().getDocument());
    ostrm.flush();
        } catch (IOException io) {
    // should put in status panel
    System.out.println("Write Errors!");
    System.err.println("IOException: " + io.getMessage());
        }
    }
        }另:我现在就是在JDK的Sample中的Stylepad.jar中打包的几个Java文件基础上进行修改,这个类也是现成的,不是我写的。所以……
    惭愧!希望能够指点迷津。
      

  3.   

    对了,你的那段程序在我中文系统的环境下怎么出错了!
    java.io.NotSerializableException: java.lang.Object
    我都搞不懂了,难道是SUN对中文的支持问题?
    怎么会日文环境可以,而中文不行?!
    麻烦看看,谢谢!