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().getRea lPath("/") +"/temp/te st.txt";
Writer wout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath) ,java.nio. charset.Ch arset.forN ame("UTF-8 ")));
wout.write(Content );
wout.close();
out.println("done");
---------------------//
What am i doing wrong ?
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().getRea
Writer wout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath)
wout.write(Content );
wout.close();
out.println("done");
---------------------//
What am i doing wrong ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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