Link to home
Start Free TrialLog in
Avatar of Xyleen
Xyleen

asked on

File unwilling to write in UTF-8, always ansi

I've got a simple question, but i cannot seem to find a solution
I want to write a file as utf-8 but it keeps saving it as ansi

This is my code

//--------------------
<%@ page import='java.io.*'  pageEncoding="UTF-8"%>

String Content = "test";
String filePath = getServletContext().getRealPath("/")+"/temp/test.txt";
Writer wout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath),java.nio.charset.Charset.forName("UTF-8")));
wout.write(Content );
wout.close();
out.println("done");
---------------------//

What am i doing wrong ?
ASKER CERTIFIED SOLUTION
Avatar of elfe69
elfe69
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Xyleen
Xyleen

ASKER

Hello,


Found the solution, only when i manually enter an utf- escaped character the file is recognised as UTF-8 by notepad.

I think notepad was the problem, not the file writing

So if i just change:

String Content = "\u00A3\u00A7\u2211";

the file encoding is recognised as utf-8