Mega Code Archive

 
Categories / Java / File Input Output
 

Display file contents in hexadecimal

import java.io.FileInputStream; public class Main {   public static void main(String[] args) throws Exception {     FileInputStream fis = new FileInputStream("/home/username/data.txt");     int i = 0;     int count = 0;     while ((i = fis.read()) != -1) {       if (i != -1) {         System.out.printf("%02X ", i);         count++;       }       if (count == 16) {         System.out.println("");         count = 0;       }     }     fis.close();   } }