title: Alternative to printing line when the string reaches \n, while still using fileinputstream
body: <pre><code>    File tempFile = new File(loadedFileName);
      FileInputStream datStream = new FileInputStream(tempFile);
      InputStreamReader readDat = new InputStreamReader(datStream);
      int data = readDat.read();
      String temp = "";
  
      // keeps reading in one character at a time and returns -1 if there are no more          
      //  characters
      while(data != -1){  
          char datChar = (char)data;
          if(temp.length() &gt; 2){
              if((temp.substring(temp.length()-1)).equals("\n")){
                  String[] arrayTemp = temp.split("\\|");
  
                  if(Float.valueOf(arrayTemp[columnNumber-1]) &gt; value){
                      System.out.print(temp); 
                  }
                  temp = "";
              }
          }
          temp = temp+datChar;
          data = readDat.read();
      }
  </code></pre>
  
  <p>The code reads in a file character by character and appends it to a string. Once it reaches a new line it will split the string into an array and then checks to see if a value in that array matches and prints out the string before it was split.</p>
  
  <p>The problem with this code is that even though it gets most of the job done, because of how it is in a while loop where it checks to see if it reaches the end, which if it does it returns -1. This makes it so that I can't print the last line of the file because there is no new line at the end of the file,  so it kills the loop before it gets to print out the last line. </p>
  
  <p>An example of a few lines being read in.</p>
  
  <p>This | world |  is | brown | and | dirty|<br>
  24 | hours | are | in | day| Hello|  </p>
  
  <p>Can't store the whole file into an array, can't use a buffered reader, I've tried doing something like counting the number of "|" but I can't seem to get that to work. So in this case if it counted to  6 pipes it would then split and then check before printing. Which I think would solve the problem of not printing the last line. Here is how I tried to implement the count for the |.</p>
  
  <pre><code>    while(data != -1){  
          char datChar = (char)data;
          // checks to make sure that temp isn't an empty string first
          if(temp.length() &gt; 2){
              // checks to see if a new line started and if it did splits  the current string into an array.
              if((temp.substring(temp.length()-1)).equals("\\|")){
                  if(count == 6){
  
                  String[] arrayTemp = temp.split("\\|");
  
                  //then checks the variable in the array col and compares it with a value and prints if it is greater.
                  if(Float.valueOf(arrayTemp[columnNumber-1]) &gt; value){
                      System.out.print(temp); 
                  }
                  temp = "";
                  count = 0;
                  }
              }
          }
          temp = temp+datChar;
          data = readDat.read();
      }
  </code></pre>