本人初学,现在只会将文件读取出来,请问如果要实现上面的效果,应该怎么处理呢?请最好给出示例代码多谢!!!!!!!!

解决方案 »

  1.   

    try {
          RandomAccessFile file = new RandomAccessFile("F:\\a.txt", "rw");
          ArrayList array = new ArrayList();
          while(file.getFilePointer() < file.length()){
            String a = file.readLine();
            a += "gongchajkhsfhsdjfhjskfhjskhfjksfjs\r\n";
            array.add(a);
          }
          file.seek(0);
          Iterator it = array.iterator();
          while(it.hasNext()){
            file.writeBytes((String)it.next());
          }
        }
        catch (Exception ex) {
        }
    我实在是没办法了
      

  2.   

    File outFile = new File("file.txt");
    RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;
    while ((str = in.readLine()) != null) {
           // str就是读取到的一行
           //进行你的处理,比如str=str+"end";
           waf.seek(waf.length()); // 指向新文件的末尾
           waf.writeBytes(result); // 写入到新文件
    }waf.close();新文件就是修改后的内容了
      

  3.   

    File outFile = new File("file.txt");
    RandomAccessFile waf = new RandomAccessFile(outFile, "rw");String str;
    while ((str = in.readLine()) != null) {
           // str就是读取到的一行
           //进行你的处理,比如str=str+"end";
           waf.seek(waf.length()); // 指向新文件的末尾
           waf.writeBytes(str); // 写入到新文件
    }waf.close();新文件就是修改后的内容了