五个客户的材料存储在名为“Customer.txt”的文件中。第六个客户的材料必须添加到现有文件的内容。识别以下解决方案中哪个最能满足所述要求,。
/* entry为包含要写到文件的数据的串 */

1. RandomAccesFile logFile=new RandomAccessFile(“Customer.txt”, “rw”);
logFile.writeBytes(entry);2. RandomAccesFile logFile=new RandomAccessFile(“Customer.txt”, “rw”);
logFile.seek(logFile.length());
logFile.writeBytes(entry);3. FileOutputStream fswriter=new FileOutputStream(“Customer.txt”, true);
fswriter.write(entry.getBytes());4. FileOutputStream fswriter=new FileOutputStream(“Customer.txt”, false);
fswriter.write(entry.getBytes());

解决方案 »

  1.   

    3. FileOutputStream fswriter=new FileOutputStream(“Customer.txt”, true);
    fswriter.write(entry.getBytes());
    1,4会覆盖掉原有的5个数据
    2的理由没有想出来
    只是感觉没3好用若有错误
    还望楼下指正
      

  2.   

    2好像是不行的;
    public final void writeBytes(String s)
                          throws IOException;
    这个的参数是个字符串;题目中的entry应该是个字节数组;
      

  3.   

    选3.因为 entry 是 String 字符串, 所以排除2的 writeBytes(String s)方法.