Meaningless Drivel is fun!*
The moose likes I/O and Streams and the fly likes Writing and reading string to/from a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Writing and reading string to/from a file" Watch "Writing and reading string to/from a file" New topic

Writing and reading string to/from a file

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I've developed a program that these account information from user and then write them to a file and them back to display on console
The fields of each account:
account number(long)8 bytes
Surname(string)15*2=30 bytes
initials(string)3*2=6 bytes
balance(float)4 bytes
I know that long take 8 bytes and float take 4 bytes but my problem in understanding the size of string ......What force us to multiply the size of string by 2???
meaning , why don't we take the size as it is?

I Hear I Forget, I See I Remember, I Do I Understand.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064

Strings are collection of characters and each characters is of size=2 bytes

Mohamed Sanaulla | My Blog
Greg Charles

Joined: Oct 01, 2001
Posts: 2835

Does that answer your question Roger? Unlike older languages like C, Java uses Unicode for Strings. Each Unicode character is 16 bits, or 2 bytes.
Don't get me started about those stupid light bulbs.
subject: Writing and reading string to/from a file
Similar Threads
object Memory
Problem in framing or understanding the exact approach for the given specification
Is my understanding of what Bill Brogdon says in his book correct?
why ceil & floor accepts int