TextReader

import java.io.InputStream;

 ////////////////////////////////////////////////////////////////////////////////
 // This is a text resourse,
 // and is a .txt file
 // can be made in Word,
 // saved as a plain text
 // and using UTF-8 encoding.
 //Christian Sarmiento -> Dr. Gerardo Ayala

  class TextReader
  {
  //attributes
  InputStream inputStream;

  //constructor
  public TextReader(String textFileRoute)
  {
      inputStream = this.getClass().getResourceAsStream(textFileRoute);
  }


  //methods

   public String getContent()
    {
     //Variables
       StringBuffer stringBuffer = null;
       int aByte;

       try
       {
           stringBuffer = new StringBuffer();
           //reads the file
           aByte=0;
           while ((aByte = inputStream.read())!= -1)
           {
                stringBuffer.append((char) aByte);
           }//end while

           // hahaha!!! it needs to remove some junk,
           //I do not know why it happens...sorry
           //only for files created with Word (.docx), we need the line:
           //stringBuffer.delete(0,3);
        }//end try
        catch (Exception exception)
        {
          System.out.println("Unable to read file: "+ exception);
        }//end catch

        return stringBuffer.toString();
    }//end getContent

  } //end class  UdlaTextFileResource
Comments