Article View: borland.public.jbuilder.java.language
Article #8171Writing Bytes to File
From: Henry Michals
Date: Mon, 09 Apr 2001 00:58
Date: Mon, 09 Apr 2001 00:58
39 lines
2633 bytes
2633 bytes
I'm trying to create a bitmap file using the data in an old .rc file. For
example, the input data looks as follows:
BOXIN BITMAP LOADONCALL MOVEABLE DISCARDABLE
{
'42 4D 56 02 00 00 00 00 00 00 76 00 00 00 28 00'
'00 00 1E 00 00 00 1E 00 00 00 01 00 04 00 00 00'
'00 00 E0 01 00 00 00 00 00 00 00 00 00 00 00 00'
'00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80'
'00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80'
}
I'm using the following to create the binary file:
FileReader filereader = new FileReader(rcfile);
LineNumberReader linereader = new LineNumberReader(filereader);
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter outwriter = new OutputStreamWriter(out);
String nextLine = linereader.readLine().trim();
while (nextLine.charAt(0) != '}') {
StringTokenizer tokenizer = new StringTokenizer(nextLine, "' ");
while (tokenizer.hasMoreTokens()) {
String token = tokenizer.nextToken();
int hexdata = Integer.parseInt(token, 16);
outwriter.write(hexdata);
}
nextLine = linereader.readLine().trim();
}
outwriter.close();
The problem that I'm having is with the '80' values in the resource file.
It seems that 'outwriter.write(hexdata)' writes out 0x3F to the output file
rather than 0x80.
I suspect the heart of the problem lies with the fact that bytes are signed
in Java.
But I don't know the right way of doing this.
Can anyone suggest how this should be done?
Thanks.
Technical Details
Message-ID:
<LO7A6.180546$A6.41505533@news4.rdc1.on.home.com>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!cyclone2.usenetserver.com!e420r-sjo4.usenetserver.com!news-out.usenetserver.com!newshub2.rdc1.sfba.home.com!news.home.com!news4.rdc1.on.home.com.POSTED!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,cf1bb8cb466e7741,start X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-04-08 18:00:07 PST Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!cyclone2.usenetserver.com!e420r-sjo4.usenetserver.com!news-out.usenetserver.com!newshub2.rdc1.sfba.home.com!news.home.com!news4.rdc1.on.home.com.POSTED!not-for-mail From: "Henry Michals" <henrymichals@netscape.net> Newsgroups: borland.public.jbuilder.java.language Subject: Writing Bytes to File Lines: 42 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: <LO7A6.180546$A6.41505533@news4.rdc1.on.home.com> Date: Mon, 09 Apr 2001 00:58:19 GMT NNTP-Posting-Host: 24.112.107.91 X-Complaints-To: abuse@home.net X-Trace: news4.rdc1.on.home.com 986777899 24.112.107.91 (Sun, 08 Apr 2001 17:58:19 PDT) NNTP-Posting-Date: Sun, 08 Apr 2001 17:58:19 PDT Organization: Excite@Home - The Leader in Broadband http://home.com/faster