title: How to insert a counter into a Stream<String> .forEach()?
body: <pre><code>FileWriter writer = new FileWriter(output_file);
      int i = 0;
  
      try (Stream&lt;String&gt; lines = Files.lines(Paths.get(input_file))) {
          lines.forEach(line -&gt; {
              try {
                  writer.write(i + " # " + line + System.lineSeparator());
              } catch (Exception e) {
                  e.printStackTrace();
              }   
          }
                      );
          writer.close();
      }
  </code></pre>
  
  <p>I need to write the line with the line number, so I tried to add a counter into the .forEach(), but I can't get it to work. I just don't know where to put the i++; into the code, randomly screwing around didn't help so far.</p>