永发信息网

怎样将一个文本文件转换成十六进制形式

答案:2  悬赏:0  手机版
解决时间 2021-02-14 15:49
  • 提问者网友:听门外雪花风
  • 2021-02-14 03:52
怎样将一个文本文件转换成十六进制形式
最佳答案
  • 五星知识达人网友:从此江山别
  • 2021-02-14 04:01
I hope the code below is what you want.
Could you just describe your requirement much detail, like :
we have a data file, which is binary:
58 00 00 00 B8 1F 00 00 F1 54 C8 2A 1B DF F3 AA
I want it to be:
.......

In fact the 16 radix data you see is just a way for representation, you might want to see the result with 10 radix, but the value is still kept the same, correct?

Java code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
BufferedInputStream in = null;
BufferedOutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(FILENAME));
out = new BufferedOutputStream(new FileOutputStream(FILEOUT));
byte[] buff = new byte[60];
int cnt = in.read(buff, 0, 60);
for (int i =0; i < cnt; ++i) {
String val = Byte.toString(buff[i]);
out.write(Byte.valueOf(val, 10));
}
} finally {
if (null != in)
in.close();
if (null != out)
out.close();
}
全部回答
  • 1楼网友:逃夭
  • 2021-02-14 05:03
private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click dim b as new filestream("123.txt", filemode.create, fileaccess.write) ' filemoad.create 创建文件,fileaccess.write能够向文件写入。 dim a as new streamwriter(b) 'streamwrite写入文本 try a.writeline("here is the text") a.write("this text is stored in a file ." & controlchars.crlf) a.writeline("and now you can read it.") a.close() msgbox("wrote text data to the file .") catch ex as ioexception msgbox(ex.message) end try end sub private sub button2_click(byval sender as system.object, byval e as system.eventargs) handles button2.click dim c as new filestream("123.txt", filemode.open, fileaccess.read) dim d as new streamreader(c) try while d.peek() > -1 textbox1.text &= d.readline() & controlchars.crlf end while d.close() catch ex as ioexception msgbox(ex.message) end try end sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯