1

Inside the database table there is a file named ♥-You-Got-Me-♥[www.savevid.com].mp4. I need to get the name of this file and save it in text file. But the way I am saving,I see ? instead of .How do I store text in Unicode ?

The way I am doing is :

String name = Foo.getNameFromTheTable();
PrintWriter writer = new PrintWriter(file);
writer.println(name);
writer.close();

But this doesn't store the text in unicode form.

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

1 Answers1

1

From docs:

Prints a string. If the argument is null then the string "null" is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

That's the reason of problem.

Instead, use FileOutputStream and OutputStreamWriter:

OutputStreamWriter(OutputStream out, String charsetName) 
Create an OutputStreamWriter that uses the named charset.

See solution: https://stackoverflow.com/a/1001568/1360074

Community
  • 1
  • 1
Nikolay Kuznetsov
  • 9,467
  • 12
  • 55
  • 101