title: Reading ascii file line by line - Java
body: <p>I am trying to read an ascii file and recognize the position of newline character "\n" as to know which and how many characters i have in every line.The file size is 538MB. When i run the below code it never prints me anything.
  I search a lot but i didn't find anything for ascii files. I use netbeans and Java 8. Any ideas??</p>
  
  <p>Below is my code. </p>
  
  <pre><code>String inputFile = "C:\myfile.txt";
  FileInputStream in = new FileInputStream(inputFile);
  FileChannel ch = in.getChannel();
  int BUFSIZE = 512;
  ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE);
  Charset cs = Charset.forName("ASCII");
  
  while ( (rd = ch.read( buf )) != -1 ) {
          buf.rewind();
          CharBuffer chbuf = cs.decode(buf);
  
          for ( int i = 0; i &lt; chbuf.length(); i++ ) {
               if (chbuf.get() == '\n'){
                  System.out.println("PRINT SOMETHING");
               }
          }
  }
  </code></pre>