import java.io.*; import java.util.*; public class ReadBinFile { public static void main(String [] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter filename: "); String readFilename = sc.next(); File readFile = new File(readFilename); if( !readFile.isFile() ) { System.err.println("Input file does not exist or is not a regular file!"); return; } if( !readFile.canRead() ) { System.err.println("Input file is not readable!"); return; } try { byte []buffer = new byte[2048]; FileInputStream in = new FileInputStream(readFile); int read_len; while( (read_len = in.read(buffer)) != -1 ) { } in.close(); } catch( IOException ex ) { ex.printStackTrace(); } } }