HOW detect EOF at below code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Leonidas Savvides
    New Member
    • Aug 2010
    • 17

    #1

    HOW detect EOF at below code

    HOW detect EOF at below code? what put in place of
    ( i<3306 )
    ???

    Code:
       public mergerTxt()
       {
          try 
         {
    File file = new File( "us-skype.lang" ); // get file name
    File fileRu = new File( "ru-skype.lang" ); // get file name
    File file2 = new File( "skype6bufferedAll.lang" ); 
    		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream (file), "UTF-8"));
    		BufferedReader readerRu = new BufferedReader(new InputStreamReader(new FileInputStream (fileRu), "UTF-8"));
    		BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file2), "UTF-8")); 
             String result; // result from checking file
             String result2; // result from checking file
             String result3; // result from checking file
             int dot ;
    		 int dot2;
             int i=1;		 
             // file does exist
             if ( file.exists() ) 
             { 
            while  ( i<3306 ) 
                {   
    			i++;
                   result = reader.readLine(); // read a line from file
                   result2 = readerRu.readLine(); // read a line from file
                dot = result.lastIndexOf("=");
                dot2 = result2.lastIndexOf("=");
    		    result3 = result.substring(dot + 1) + " = " + result2.substring(dot2 + 1);
    			output.write( result3 + "\n" ); // output line of file
    
    
                } // end while
             } // end if
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Check if the returned character is null. If it is null that mean it is eof. Check API documentation for further information.

    Regards
    Dheeraj Joshi

    Comment

    • Leonidas Savvides
      New Member
      • Aug 2010
      • 17

      #3
      I used below but the resulting file rather have 3306 lines (as the two merged files eng(1)=ru(2))ha s only 3201 lines, this is memory problem...how to fix?
      Code:
                  while  ( true ) 
                  {   
      			i++;
                     result = reader.readLine(); 			   if (result==null) { break; }
                     result2 = readerRu.readLine(); 
      ......................

      Comment

      Working...