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 ?
JSP

Avatar of undefined
Last Comment
Xyleen
ASKER CERTIFIED SOLUTION
Avatar of elfe69
elfe69
Flag of Switzerland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
JSP
JSP

JavaServer Pages (JSP) allow the development of dynamically generated web pages. It uses the Java programming language; JSP pages are translated into servlets at runtime, with each servlet being cached and reused until the JSP is modified. JSP allows Java code to be interleaved with static web markup content, so the resulting page can be compiled and executed on the server to deliver the content.

16K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo