File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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
Author

Writing and reading string to/from a file

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

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?

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

Joined: Sep 08, 2007
Posts: 3068
    
  33

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


Mohamed Sanaulla | My Blog
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2848
    
  11

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Writing and reading string to/from a file