用s.writeObject("\n");但是不行,只是乱码增多了。

解决方案 »

  1.   

    writeObject写到文件里的是String类的序列化内容,当然不能正确查看了,写字符串用PrintStream比较好。而且输出“\n”和“\r\n”都不是很好的方法,因为不同的平台回车符是不一样的,PrintStream.println可以解决你的问题。
      

  2.   

    用PringStream怎样写到文件中?我下面的程序段就没有把String“dfd”写到文件中去。
    File MyPath=new File("f:\\temp");
    File objFile=new File(MyPath,"Test.java");
    FileOutputStream f = new FileOutputStream(objFile);
    ObjectOutputStream s = new ObjectOutputStream(f);
    PrintStream sP=new PrintStream(s);
             sP.println("dfd");
      

  3.   

    ObjectOutputStream s = new ObjectOutputStream(f);
    为什么非得用ObjectOutputStream啊?PrintStream sP=new PrintStream(f);
    sP.println("dfd");
    sP.flush();
    sP.close();