title: Read file by line and write by line with the line number added
body: <p>The solution works and is capsulated and everything is fine, but .... I wonder if there is a better solution, maybe with new functions from Java 8 or some other improvements that can be done?</p>
  
  <p>Main.java    </p>
  
  <pre><code>package test;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.List;
  
  class Main {
  public static void main(String[] args) {
  
      // zum speichern der Zeilen je Arrayfeld
      List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
  
      // Inputdatei bestimmen
      File file = new File("C:\\...\\test.txt");
  
      // Inputdatei zeilenweise einlesen
      ReadFile readfile = new ReadFile();
      try {
          // und in der ArrayList "lines" speichern
          lines = readfile.byLine(file);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
      // Inputdatei zeilenweise schreiben (neue Datei) mit Zeilennummer
      WriteFile writefile = new WriteFile();
      try {
          writefile.byLine(lines);
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  }   
  }
  </code></pre>
  
  <p>ReadFile.java</p>
  
  <pre><code>package test;
  
  import java.util.List;
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.ArrayList;
  
  public class ReadFile {
  
  List&lt;String&gt; lines = new ArrayList&lt;String&gt;();
  String line;
  int lineNumber = 0;
  
  protected List&lt;String&gt; byLine(File file) throws IOException {
      // Inputdatei einlesen
      FileReader fileReader = new FileReader(file);
      BufferedReader bufferedReader = new BufferedReader(fileReader);
  
      // schauen ob Zeilenende erreicht wurde
      while ((line = bufferedReader.readLine()) != null ) {
          // Zeilen in Array speichern
          lines.add(line);
      }
  
      // Reader schließen
      bufferedReader.close();
      // Array zurückgeben
      return lines;
  }
  }
  </code></pre>
  
  <p>WriteFile.java</p>
  
  <pre><code>package test;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.List;
  
  public class WriteFile {
  
  int lineNumber = 1;
  
  protected void byLine(List&lt;String&gt; lines) throws IOException {
      // neue Datei erstellen
      PrintWriter writer = new PrintWriter("C:\\...\\test2.txt", "UTF-8");
      // für jeden String (eingelesene Zeile) in der Arraylist
      for( String line: lines) {
          // Counter für die Zeilennummern
              writer.println("*/ " + lineNumber + " /*" + " " + line);
              lineNumber++;
          }
      // Writer schließen
      writer.close(); 
      }
  
  }
  </code></pre>