title: Java: Reading the Trailing New Line from a Text File
body: <p>How can you get the contents of a text file while preserving whether or not it has a newline at the end of the file?  Using this technique, it is impossible to tell if the file ends in a newline:</p>
  
  <pre><code>BufferedReader reader = new BufferedReader(new FileReader(fromFile));
  StringBuilder contents = new StringBuilder();
  
  String line = null;
  while ((line=reader.readLine()) != null) {
    contents.append(line);
    contents.append("\n");
  }
  </code></pre>