Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Writing and reading string to/from a file

 
Roger Fed
Ranch Hand
Posts: 82
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hell
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?
 
Mohamed Sanaulla
Saloon Keeper
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Strings are collection of characters and each characters is of size=2 bytes
 
Greg Charles
Sheriff
Posts: 2993
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic