title: Can I manipulate LineIterator from Apache Commons IO to set its start line in file?
body: <p>I have two large tab delimited text files. What I am trying to do is compare both of them and write changes to a new file. For that I am using Apache Commons IO java library. Inputs are done as streams. Since it doesn't need to be fancy and there is a set structure of files, principle of compare is simple. Go through first file and use part of line to search for it in second file.
  As you can see its looping through second file for every line of first file (simplified the example as it does a bit more parsing on the line for boths to determine the key and parts to check changes in). Since key will always be unique and I can use part of key to know where lines with that part starts in file. My problem I have no idea how to manipulate lineIterator so it starts from said lines and not from beginning of file. so is it even possible to manipulate? If so how? Or should I look at some other way?</p>
  
  <pre><code>public static void main(String[] args) throws IOException {
      File theFile = new File("first.txt");
      File oldFile = new File("second.txt");
      File targetFile = new File("changes.txt");
      int counter = 0;
      boolean found = false;
      String key = null;
      LineIterator update = FileUtils.lineIterator(theFile, "UTF-8");
      try {
          while (update.hasNext()) {
              //update.nextLine();
              counter++;
              String line = update.nextLine();
              String[] splitted = line.split("\\t");
              key = splitted[0];
              LineIterator old = FileUtils.lineIterator(oldFile, "UTF-8");
              found = false;
              while (old.hasNext() &amp;&amp; !found) {
                  String oldLine = old.nextLine();
                  String[] content = oldLine.split("\\t");
                  if (oldLine.startsWith(key)) {
                      if (!content[2].equals(splitted[2])) {
                          System.out.println(counter + " [CHANGE FOUND]");
                          FileUtils.writeStringToFile(targetFile, line+"\t[TEXT CHANGE]\n", "UTF-8", true);
                      }
                      found = true;
                  }
              }
              if (!found) {
                  System.out.println(counter + " [NEW LINE]");
                  FileUtils.writeStringToFile(targetFile, line+"\t[NEW LINE]\n", "UTF-8", true);
              }
              old.close();
              key = null;
          }
      } finally {
          LineIterator.closeQuietly(update);
          System.out.println("Checking Done");
      }
  }
  </code></pre>