// BytesFromFile.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-06-28 File created. // 2005-06-28 Last modification. import java.util.* ; import java.io.* ; // Classes for file handling. class BytesFromFile { public static void main( String[] command_line_parameters ) { if ( command_line_parameters.length == 1 ) { try { FileInputStream file_to_read = new FileInputStream( command_line_parameters[ 0 ] ) ; byte[] bytes_from_file = new byte[ 50 ] ; int file_size_in_bytes = 0 ; boolean bytes_still_available_in_file = true ; while ( bytes_still_available_in_file == true ) { int number_of_bytes_read = file_to_read.read( bytes_from_file ) ; if ( number_of_bytes_read > 0 ) { file_size_in_bytes = file_size_in_bytes + number_of_bytes_read ; System.out.print( " " + number_of_bytes_read ) ; // This loop does not do anything to the read data. } else { bytes_still_available_in_file = false ; } } System.out.print( "\n " + file_size_in_bytes + " is the file size. " ) ; file_to_read.close() ; } catch ( Exception caught_exception ) { System.out.print( "\n Cannot process file " + command_line_parameters[ 0 ] ) ; } } else { System.out.print( "\n You have to command this program as: \n" + "\n BytesFromFile file.ext \n") ; } } }