We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.PrintStream;
public class FileUtils {
public static void hexDump(PrintStream out, File file) throws IOException {
InputStream is = new FileInputStream(file);
int i = 0;
while (is.available() > 0) {
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder(" ");
out.printf("%04X ", i * 16);
for (int j = 0; j < 16; j++) {
if (is.available() > 0) {
int value = (int) is.read();
sb1.append(String.format("%02X ", value));
if (!Character.isISOControl(value)) {
sb2.append((char)value);
}
else {
sb2.append(".");
}
}
else {
for (;j < 16;j++) {
sb1.append(" ");
}
}
}
out.print(sb1);
out.println(sb2);
i++;
}
is.close();
}
public static void main(String args[]) throws Exception {
// dump to the console
FileUtils.hexDump(System.out, new File("c:/temp/nvir.log"));
// dump to a file
FileUtils.hexDump(new java.io.PrintStream("c:/temp/nvir.hex"), new File("c:/temp/nvir.log"));
System.out.println("Done.");
}
}