Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

japanese character encoding

 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am getting string value from one FTP server (this holds name of the file, and we are using Apache FTP API to get filenames), while creating a file in local maching with same name its not creating with japanese characters, its puting some junk charcters. Please help me in creating file with same name. I am using following code to get file name and to create new file

String sFilename = ftpFile.getName(); // ftpFile is apache FTPFile object
String jpName = new String(sFilename.getBytes("UTF-8"),Charset.forName("SJIS"));
File targetFile = new File(jpName);
targetFile.createNewFile();

but this code is not working properly

Nuthan
 
Alan Moore
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't need to do any conversions. The FTP client should have converted the name to a valid Java string, and the File class should convert that to the encoding that's expected by the operating system.

What kind of garbage characters are you seeing? If it's question marks (?) you have an encoding problem, but if you see little boxes, it means the font you're using doesn't support those characters.

By the way, never do this: Unless the string consists entirely of seven-bit ASCII characters, that command is guaranteed to produce garbage. And if it is pure ASCII, the command will have no effect.
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am seeing ? in the string, i tried by removing encoding/decoding also. still its not wroking properly
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nuthan kumar:
i am seeing ? in the string, i tried by removing encoding/decoding also. still its not wroking properly


What do you view the String in? Does it support these Japanese chacacters?
 
nuthan kumar
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actual file name 1-計画.tif and while trying to print that name its printing 1-??.tif
 
David BalaĹžic
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Print the name in some SWING GUI element (like JButton or JLabel), as the Windows command prompt does not support Unicode.
Also print the string after each manipulation, to see where it breaks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic