File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Writting to the DB File - totally lost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Writting to the DB File - totally lost" Watch "Writting to the DB File - totally lost" New topic
Author

Writting to the DB File - totally lost

Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
How do we write to the DB file in 8 bit US ASCII?
I was thinking of using String(byte[] bytes, String charsetName)
where charsetName was US ASCII, but US ASCII is 7 bits!!!
Can you just use RandomAccessFiles writeUTF?
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Hello Bill,
There are 6 standard charsets in the class Charset. You cannot use US-ASCII, but why not try ISO-8859-1? UTF is different from 8 bit US ASCII becuase they use 16 bits to present one character.
Regards.
Rick


SCJD 1.4
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
You cannot use US-ASCII

But my instructions say "The character encoding is 8 bit US ASCII".
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Bill and Rick,
Bill
(...) where charsetName was US ASCII, but US ASCII is 7 bits!!!

Rick
You cannot use US-ASCII

Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.
Best,
Phil.
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
Hi Bill,
To read in data to within the DB I am using

I imagine that you confusion is coming from :
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.

I then write the String out as:

I am not specifying the charset when writing is that right?
Chris


SCJP 1.2, SCWCD, SCBCD
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
QUOTE]Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.

According to javasoft.com its 7 bit, or am I missing something:
http://java.sun.com/j2ee/1.3/docs/tutorial/doc/Encodings.html
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
Mmh... I think that you must use US-ASCII to fulfil the requirements. It's a 8 bits character set, with, among the 8 bits, one simply unused.

According to javasoft.com its 7 bit, or am I missing something:
http://java.sun.com/j2ee/1.3/docs/tutorial/doc/Encodings.html
Rick Lu
Ranch Hand

Joined: Mar 25, 2003
Posts: 47
Hi,
Sorry about that. The sentence should be "You cannot use US-ASCII 7 bits". You can see that
ISO-8859-1
This is the character set for Western European languages. It's an 8-bit encoding scheme in which every encoded character takes exactly 8-bits. (With the remaining character sets, on the other hand, some codes are reserved to signal the start of a multi-byte character.)

This implies ISO-8859-1 is 8 bit scheme. I suppose that should be fine with our assignment.
Rick
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Again, in US-ASCII, there are 8 bits, but only 7 are realy used. Take a look at the individual bytes in your sample file. They're all in the range 0-127, except possibly for the delete flag or other non-text data. Each 8-bit byte represents a character. If you don't allow that the 8th bit is simply unused, that would mean that 7 bytes = 56 bits = 8 characters. You could try to write a routine that would decode a set of 7 bytes into 8 chars, assuming no unused bits are included - but if you try that on the sample file, you'll just get gibberish. All common character encodings are implicitly built around 8-bit bytes. When they say 7-bit, they're just ignoring the 8th bit.


"I'm not back." - Bill Harding, Twister
Bill Robertson
Ranch Hand

Joined: Mar 21, 2003
Posts: 234
you sound very confident. you have me sold. thanks jim!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writting to the DB File - totally lost