有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java扁形虫从nunber行读取文件

有没有办法从相应的行号中读取平面文件?我听说了唱片识别标签,但不确定要传递什么

没有匹配的字符串,我只需要从特定的libne编号中读取


共 (1) 个答案

  1. # 1 楼答案

    IOUtil是用于访问平面文件的实用程序类

    IOUtil。lineIterator(Reader Reader)可用于从line Number读取文件

    LineIterator it = IOUtils.lineIterator(new BufferedReader(new FileReader("inputfile.txt")));
     for (int lineNoInFile = 0; it.hasNext(); lineNoInFile++) {
        String outputLine = (String) it.next();
        if (lineNoInFile == inputLineNumber) {
            return outputLine;
        }
     }
    

    要读取多行,可以使用IOUtils.readLines

    int outputLinenumber = 25;      
    List<String> lines = IOUtils.readLines(new FileInputStream(new File("inputfile.txt")), "UTF-8");
    for (int index = outputLinenumber; index<=lines.size();index ++){
      //Iterate the Files
    }
    

    这只是示例代码