请问下如何让一个流IO程序更新文件部分内容呢?好心朋友帮帮我哈!谢谢了

解决方案 »

  1.   

    RandomAccessFile reader = null;
    try {reader = new RandomAccessFile(filepath, "rw");
    String tmpString = null;
    int line = 1;
    reader.writeByte('@');
    while ((tmpString = reader.readLine()) != null) {
    System.out.println(tmpString);
    if(tmpString.length() > 0){if (tmpString.charAt(0) != '@') {reader.writeByte('@');} else {
    System.out.println("(line:" + line + ":"+ tmpString + ")");
    }
    }
    line++;
    }reader.close();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    if (reader != null) {
    try {
    reader.close();
    } catch (IOException e1) {
    }
    }
    }