Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2008, 04:53 AM
Member
 
Join Date: Feb 2008
Posts: 1
ranoosh is on a distinguished road
writing and reading unicode characters from a file
Hello everybody!

I have been trying for ages now to read and write unicode characters form a file and into a file but instead of characters i get funny shapes and question marks.

any idea how java handles unicode characters? and why i can print out unicode characters to screen just fine but I cannot save the into a file properly?

I am using linux, i have tried using windows but it did not work at all.


Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-27-2008, 03:45 AM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 720
Nicholas Jordan is on a distinguished road
Java strings are natively UTF-16

Use filetypes with the name Reader in them.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 09-27-2008, 06:35 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,412
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
In simple word, try something like this. That's what Jordan try to pointed you.

Code:
BufferedReader bufReader = new BufferedReader( new InputStreamReader(new FileInputStream(file_name), "UTF-16"));
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 09-27-2008, 06:58 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Gone to Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
i can print out unicode characters to screen just fine but I cannot save the into a file properly?
What class are you using to write the unicode characters?
Do you really want unicode or do you want ASCII?
Unicode characters use 2 bytes. With ASCII text every other byte will be a binary 0 which will display as a ? or square with most text editors. Do you have a hex editor that you can use to look at the files you are reading and writing?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 09-28-2008, 06:34 AM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 462
fishtoprecords is on a distinguished road
Quote:
Originally Posted by Norm View Post
Unicode characters use 2 bytes.
This is mostly true. For most languages, the characters are encoded in 16 bit values, which are typically called "two bytes".

But the point of unicode is to be able to write software that supports any language spoken or written on this planet. There are some lanugages that use three byte representations. These can still be stored as UTF-16, altho I think some of them end up being more like UTF-32.

More importantly, all String objects in Java are Unicode. Its easy inside Java.
Storing the strings to/from disks, printers, etc. is the challenge.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading data from Micrsoft excel and writing to notepad abhishek.jain New To Java 2 06-18-2008 02:24 PM
Reading/Writing a File using byte array Java Tip Java Tips 0 01-16-2008 12:41 PM
Reading/Writing files through Applet Java Tip Java Tips 0 12-15-2007 10:20 PM
Write unicode into file vata2999 New To Java 1 08-08-2007 05:04 PM
Help with File reading and writing baltimore New To Java 1 07-31-2007 08:47 PM


All times are GMT +3. The time now is 10:04 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org