1, the FileInputStream class function is created:
PackageCorejava;ImportJava.io.FileInputStream;Importjava.io.IOException; Public classIoutil { Public Static voidPrinthex (String Filename)throwsioexception{/*** Read the specified file inside the glory, follow the 16 output to the console, and * No output 10byte line feed*/FileInputStream in=NewFileInputStream (Filename); intb; inti = 1; while((b = in.read ())!=-1){ if(b <= 0xf){ //number of units front complement 0System.out.print ("0"); } //output is displayed in 16-binary form and separated by a spaceSystem.out.print (integer.tohexstring (b) + ""); //line breaks when each row output is greater than or equal to 10 bytes if(i++%10 = = 0) {System.out.println (); } } //close files to avoid exception errorsIn.close (); }}
2. Main function:
Package Corejava; Import java.io.IOException; Public class IOUtilTest1 { publicstaticvoid main (string[] args)throws IOException { // TODO auto-generated method stub ioutil.printhex ("e:\\ JAVA io\\testjava\\ unicom 1.txt ");} }
Java self-taught-----FileInputStream class