• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Chinese Filename

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I created a file named 你好.txt. I get into trouble when I try to running java in dos read filename from file.list() and toString(), it returns ??.txt. Here is source:

I have tried getBytes(Charset charset) in difference charset of UT-8, UTC-16 and Big5. But no luck

The file show chinese in window explore and able to be viewed in dos when I execute "dir" command.

Thanks for any help.

Keith
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java strings are in Unicode - is the console capable of displaying Unicode? I'm pretty certain that Windows Explorer uses some other character encoding internally, so it doesn't mean much that it can display those characters.
 
Keith Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of Cause, DOS able to display. As I stated, dir command show the 你好.txt

Thanks,
Keith
 
Master Rancher
Posts: 4806
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Ulf]: Java strings are in Unicode - is the console capable of displaying Unicode?

Internally a String is stored in Unicode. However when it's written to a console, it's generally converted to the platform's default encoding. For some encodings it's impossible to represent some characters, e.g. it's impossible to represent most all Asian characters in ISO-8859-1. However for a machine configured for a Chinese locale, it's quite possible that Chinese characters are supported by the default encoding - and that appears to be the case here.

[Keith]: Of Cause, DOS able to display

Did you mean "of course"? It's not at all obvious to those of us in Western countries - our environments are usually not set up to be able to display such characters.

[Keith]: I have tried getBytes(Charset charset) in difference charset of UT-8, UTC-16 and Big5.

I'm not familiar with UT-8 or UTC-16. I don't think your computer is either. Have you tried UTF-8 or UTF-16? Also, have you tried using getBytes() with no arguments? This should use your system's default encoding. Still, I think that's what your original program shown above should do too, so I don't know why it doesn't work if your console is indeed able to display these characters.

You might try looking at all your environment variables and system properties. One of these may be the name of the encoding you need to use here. I don't have a windows box available right now to look to see what environment variables are used there. And in any event my Windows system wouldn't be able to display chinese characters in the command prompt. (My Mac can, sure - but that's no use to you.) You'll have to look at the environment variables yourself to see if you can find one that looks significant. Good luck...
 
Keith Wong
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Forgot to mention, the computer has been set to Chinese display from following instruction.
http://blog.wensheng.com/2005/05/dos-chinese-under-window-xp.html

I had mistype the UTF-8 or UTF-16 instead of UT-8 or UTC-16. I had tried both with Big5 as well.

Thanks,
Keith
 
reply
    Bookmark Topic Watch Topic
  • New Topic