[英]Can I read a binary file and print out a text file in java?
I'm learning file I/O and I can read/write binary file from/to binary file , write text to binary file but I'm wondering can I read a binary file and print out a text , the content is the same when the binary file was created not the character by character? 我正在学习文件I / O,并且可以从二进制文件读取二进制文件/向二进制文件写入二进制文件,可以将文本写入二进制文件,但是我想知道我可以读取二进制文件并打印出文本吗,内容何时相同二进制文件不是按字符创建的吗?
Thanks! 谢谢!
Of course, you can; 当然可以; if you've read byte array
byte[] bytes
, you can always convert it to String: 如果您已读取字节数组
byte[] bytes
,则始终可以将其转换为String:
str = new String(bytes)
or 要么
str = new String(bytes, "UTF-8")
and then 接着
System.out.println(str)
But I think that doesn't make sense if the file is really binary. 但是我认为,如果文件确实是二进制的,那是没有意义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.