Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Character encoding  RSS feed

 
Mike Tilling
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was mentioned in the UrlyBird assignment:

�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 am using writeShort(short ) and writeByte (char) primitives of the RandomAccessFile type object.

The RandomAccessFile object is created is as follows :
new RandomAccessFile(file, "rw");

Does this fit with the exam specification.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mike,

I try to give you an an example.
If you have a String "aaa" and you write it in a file using the raf, the encoding is the String default "aaa" encoding.
You can change the String encoding with one on the String constructor (by example : +String(byte[], String) the String is the charsetName), if you save the String after you change its encoding you'll write the new encoding.

Why you chose to use the writeShort(short ) and writeByte (char) ?

Regards M.
 
Mike Tilling
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

writeShort is used to write two bytes, it is required in my assignement that 00 that specifies a valid record is on two bytes, writeShort this.
writeByte (char) is used to write each chatacter on one byte to fit with the assignement spec.

Regards
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!