// strings/Hex.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.// {java onjava.Hex}package onjava;import java.io.*;import java.nio.file.*;public class Hex {public static String format(byte[] data) {StringBuilder result = new StringBuilder();int n = 0;for(byte b : data) {if(n % 16 == 0)result.append(String.format("%05X: ", n));result.append(String.format("%02X ", b));n++;if(n % 16 == 0) result.append("\n");}result.append("\n");return result.toString();}public static voidmain(String[] args) throws Exception {if(args.length == 0)// Test by displaying this class file:System.out.println(format(Files.readAllBytes(Paths.get("build/classes/main/onjava/Hex.class"))));elseSystem.out.println(format(Files.readAllBytes(Paths.get(args[0]))));}}/* Output: (First 6 Lines)00000: CA FE BA BE 00 00 00 34 00 61 0A 00 05 00 31 0700010: 00 32 0A 00 02 00 31 08 00 33 07 00 34 0A 00 3500020: 00 36 0A 00 0F 00 37 0A 00 02 00 38 08 00 39 0A00030: 00 3A 00 3B 08 00 3C 0A 00 02 00 3D 09 00 3E 0000040: 3F 08 00 40 07 00 41 0A 00 42 00 43 0A 00 44 0000050: 45 0A 00 14 00 46 0A 00 47 00 48 07 00 49 01 00...*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。