作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要将文件数据转换为十六进制,并用十六进制表填充它。并且使用了seek(),您可以调用read()和printf();
public class HexEditor {
static int sixteen = 16;
public static void main(String[] args) throws IOException {
File myFile = new File("a.dat");
RandomAccessFile raf = new RandomAccessFile(myFile, "rw");
printHexTable(raf, 0);
}
public static void printHexTable(RandomAccessFile accessFile, int rownumber) throws IOException {
accessFile.seek(rownumber * sixteen);
int readByte = accessFile.read();
System.out.printf("%02X", readByte);
System.out.print("\n");
System.out.print(" H |");
for (int i = 0; i < 16; i++) {
String str = Long.toHexString(i);
System.out.print(" " + str.toUpperCase() + " |");
}
System.out.print("\n");
System.out.print("-----|");
for (int i = 0; i < sixteen; i++) {
System.out.print("------");
}
System.out.print("\n");
for (int x = rownumber; x < sixteen; x++) {
String str = Long.toHexString(x);
System.out.println(" " + str + " | ");
}
}
}
我正在尝试填充数据,我已经创建表,但如何填充十六进制数据
这是我的输出
H | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
-----|------------------------------------------------------------------------------------------------
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
a |
b |
c |
d |
e |
f |
最佳答案
最后,我找到了一种填充表格的方法
public class HexEditor {
static int sixteen = 16;
public static void main(String[] args) throws IOException {
File myFile = new File("a.dat");
RandomAccessFile raf = new RandomAccessFile(myFile, "rw");
printHexTable(raf, 0);
}
public static void printHexTable(RandomAccessFile accessFile, int rownumber) throws IOException {
int readByte = 0;
int count = 0;
// System.out.printf("%02X", readByte);
System.out.print("\n");
System.out.print(" H |");
for (int i = 0; i < 16; i++) {
String str = Long.toHexString(i);
System.out.print(" " + str.toUpperCase() + " |");
}
System.out.print("\n");
System.out.print("-----|");
for (int i = 0; i < sixteen; i++) {
System.out.print("------");
}
System.out.print("\n");
accessFile.seek(rownumber * sixteen);
int bytesCounter = 0;
for (int x = rownumber; x < sixteen; x++) {
while ((readByte = accessFile.read()) != -1) {
if (bytesCounter < sixteen) {
if (count == 0) {
System.out.print(" " + Long.toHexString(count) + " |");
count++;
}
System.out.print(" ");
System.out.printf("%02X", readByte);
System.out.print(" ");
bytesCounter++;
} else {
System.out.print("\n");
System.out.print(" " + Long.toHexString(count) + " |");
bytesCounter = 0;
count++;
}
}
System.out.print("\n");
}
}
}
关于java - 文件存入十六进制表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61351268/
当用户登录到成员(member)的唯一区域时,我试图提取其他数据,例如他们的名字以及他们的登录凭据,即电子邮件和密码,但似乎无法让查询成功输出数据.它成功登录,但我无法将任何其他内容传递到 sessi
我是一名优秀的程序员,十分优秀!