txt文件的格式如下RefereeView1/192.168.0.102
RefereeView2/192.168.0.104
ArtScore1/192.168.0.107
ArtScore2/192.168.0.114
ArtScore3/192.168.0.112
CompletionScore2/192.168.0.108
CompletionScore1/192.168.0.101
ArtScore4/192.168.0.100
DiffcultyScore1/192.168.0.109
RefereeEdit/192.168.0.105
RefereeView3/192.168.0.106比如要删除:CompletionScore1/192.168.0.101,请问如何实现?

解决方案 »

  1.   

    http://bbs.csdn.net/topics/340137683
    楼主可以参考这篇帖子可以找到你要的答案
      

  2.   

        可以将文件中的每行数据提取出来,放到指定的存储结构中,如链表、数组、Map等。
        使用Java中支持这些结构的API来处理每行数据,处理完毕后,
        再讲存储结构中的内容写回文件中。
        
      

  3.   

    每行读取,然后再写入,如果包含CompletionScore2就不写入。
      

  4.   

    可以先考虑把要删除的行的内容用正则或者什么的写好,然后readline来遍历,符合的就不写入了,不符合才写入,等同于删除了
      

  5.   

    if(txt.readLine.equals("xxx")){删除它}
      

  6.   

    public class JavaSeTest {
    public static void main(String[] args) { JavaSeTest test = new JavaSeTest();
    List<String> list;
    try {
    list = test.readFile("E:\\test.txt","CompletionScore1/192.168.0.101");
    test.writeFile("E:\\test.txt", list);
    } catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }
    } private List<String> readFile(String filePath, String str)throws IOException {
    File file = new File(filePath);
    BufferedReader reader = null;
    List<String> list = new ArrayList<String>();
    reader = new BufferedReader(new FileReader(file));
    String text = reader.readLine();
    while (text != null) {
    if (!text.trim().equals(str)) {
    list.add(text + "\r\n");
    }
    text = reader.readLine();
    }
    reader.close();
    return list;
    } private void writeFile(String filePath, List<String> list)
    throws IOException {
    File file = new File(filePath);
    if (!file.exists()) {
    file.createNewFile();
    }
    FileOutputStream outputStream = new FileOutputStream(file);
    for (String s : list) {
    outputStream.write(s.getBytes());
    }
    outputStream.close();
    }
    }