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();
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.
Joined: Feb 14, 2006
i am seeing ? in the string, i tried by removing encoding/decoding also. still its not wroking properly