Re: How to use Java to read a binary file?
- From: "Richter~9.6" <rickky@xxxxxxxxx>
- Date: 16 Feb 2007 09:21:39 -0800
On 16 Feb, 17:07, www <w...@xxxxxxxxxx> wrote:
Hi,
I have a binary file. I have no idea what is inside. They could be
numbers, or chars. I am trying to use Java to read it and print out to
the screen. Following is my program:
<Java>
import java.io.*;
public class CopyBytes {
public static void main(String[] args) throws IOException {
DataInputStream in = null;
try {
in = new DataInputStream(new
FileInputStream("binary_file_name"));
char c;
while ((c = in.readChar()) != -1) {
System.out.print(c);
}
} finally {
if (in != null) {
in.close();
}
}
}}
</Java>
The print out to screen is very, very messy. I saw Korean letters,
Chinese letters printed out. I am wondering if I did it right.
Thank you for your help.
Are you trying to print out the binary value? Give
System.out.printf("Binary value: %b", c) a try.
Regards,
Richard
.
- References:
- How to use Java to read a binary file?
- From: www
- How to use Java to read a binary file?
- Prev by Date: Re: Scatter/Gather in Java or Javascript & html (Dynamic class loading?)
- Next by Date: Re: IBM-recommended method not thread-safe?
- Previous by thread: How to use Java to read a binary file?
- Next by thread: Re: How to use Java to read a binary file?
- Index(es):
Relevant Pages
|