1

My actual file name is "парламент.xls".

But I am unable to get the same file name in java. It was coming something strange like ???????.xls The problem is coming for the non-latin words and characters. How to use my actual file name without being changed.

I tried from my side. Please refer to my below code:

String escaped_source = StringEscapeUtils.escapeJava(filename);
String encoded = new String(filename.getBytes("UTF-16"), "ISO-8859-1");
System.out.println("escaped_source------------>"+escaped_source);
System.out.println("encoded------------>"+encoded);
String abc = StringEscapeUtils.unescapeJava(escaped_source);
System.out.println("abc------------>"+abc);

Output: escaped_source------------

>\u043F\u0430\u0440\u043B\u0430\u043C\u0435\u043D\u0442.xls
encoded------------>þÿ?0@;0<5=B
abc------------>?????????.xls
Cœur
  • 37,241
  • 25
  • 195
  • 267
Varun
  • 85
  • 1
  • 7

1 Answers1

0

System.out uses platform encoding. This question is already answered here

Community
  • 1
  • 1
  • 1
    Don't link to a duplicate, mark the question as a duplicate. – Boris the Spider Jan 31 '15 at 10:48
  • Actually i have to pass this file name to a function by storing it in a string variable. How can i store this file name without being changed. The above solutions are given for printing in the console alone. So how to store the exact file name in a string variable??? – Varun Feb 02 '15 at 05:24