Results 1 to 5 of 5
- 02-08-2008, 02:53 AM #1Member
- Join Date
- Feb 2008
- Rep Power
writing and reading unicode characters from a file
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.
- 09-27-2008, 01:45 AM #2
Java strings are natively UTF-16
Use filetypes with the name Reader in them.Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor
- 09-27-2008, 04:35 AM #3
- Join Date
- Jul 2007
- Colombo, Sri Lanka
- Blog Entries
- Rep Power
In simple word, try something like this. That's what Jordan try to pointed you.
BufferedReader bufReader = new BufferedReader( new InputStreamReader(new FileInputStream(file_name), "UTF-16"));
- 09-27-2008, 04:58 AM #4i can print out unicode characters to screen just fine but I cannot save the into a file properly?
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?
- 09-28-2008, 04:34 AM #5
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.
- By abhishek.jain in forum New To JavaReplies: 4Last Post: 01-29-2009, 08:12 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 01-16-2008, 10:41 AM
- By Java Tip in forum Java TipReplies: 0Last Post: 12-15-2007, 08:20 PM
- By vata2999 in forum New To JavaReplies: 1Last Post: 08-08-2007, 03:04 PM
- By baltimore in forum New To JavaReplies: 1Last Post: 07-31-2007, 06:47 PM