使用RandomAcessFile时,为什么不能写入之后,直接读取???已经设置了RandomAccessFile random1 = new RandomAccessFile(file,"rw"),但是能写不能读啊,读了之后是空....什么也输出不了.但是重新新建一个RandomAcessFile,再用它来读就能读出来,请教哈~~~~开始能写不能读的代码:
String message = request.getParameter("messages");
     String r = (String)session.getAttribute("序号");
     File file = new File("D:/Project/textspace/",r);
      try{
     RandomAccessFile random = new RandomAccessFile(file,"rw");
     random.seek(random.length());
     random.writeUTF(message);
     random.close();
     out.print("写入成功!");
     out.print("小说内容:");
    
     String temp=null;
        while((temp=random.readUTF())!=null)
        {
         out.print("小说内容11111:");
         byte  d[]=temp.getBytes("ISO-8859-1");
            temp=new String(d); 
         out.print("<BR>"+temp);
         out.print("小说内容22222:");
        }
        random.close();
              }
   catch(IOException e){}
后面改了后能写又能读的代码:String message = request.getParameter("messages");
     String r = (String)session.getAttribute("序号");
     File file = new File("D:/Project/textspace/",r);
      try{
     RandomAccessFile random = new RandomAccessFile(file,"rw");
     random.seek(random.length());
     random.writeUTF(message);
     random.close();
     out.print("写入成功!");
     out.print("小说内容:");
     RandomAccessFile random1 = new RandomAccessFile(file,"rw");
     String temp=null;
        while((temp=random1.readUTF())!=null)
        {
         //out.print("小说内容11111:");
         byte  d[]=temp.getBytes("ISO-8859-1");
            temp=new String(d); 
         out.print("<BR>"+temp);
         //out.print("小说内容22222:");
        }
        random.close();
              }
   catch(IOException e){}