五个客户的材料存储在名为“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());
/* 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());
解决方案 »
- 使用反射机制获取类构造方法参数的困惑!
- JAVA String 如何去掉指定字符
- 当子进程结束后,如何获取JAVA中子进程的输出流余下的数据? -----另一种思考:PROCESS类有办法知道子进程是结束了还是正在运行中???
- 学JAVA,该看什么书?
- 各位:这是java的bug???
- 文件路径问题,请高手解答
- eclipse Dug 的时候,出现Source not found.怎么处理?怎么才能看到源码?不理解的看链接
- 如何发布自己编写的包?
- 请推荐java开发环境
- 有关执行存储过程返回值的问题
- java 写 oracle 的 long 字段时,中文问题怎么样解决啊?
- 欢迎加入我的java群:25250314
fswriter.write(entry.getBytes());
1,4会覆盖掉原有的5个数据
2的理由没有想出来
只是感觉没3好用若有错误
还望楼下指正
public final void writeBytes(String s)
throws IOException;
这个的参数是个字符串;题目中的entry应该是个字节数组;