File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes How to resolve Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to resolve "MalformedByteSequenceException: Invalid" " Watch "How to resolve "MalformedByteSequenceException: Invalid" " New topic

How to resolve "MalformedByteSequenceException: Invalid"

shivashankarHg shankar

Joined: Jun 26, 2009
Posts: 3
I have a simple xml files with the following tags, having some non-english characters,

<?xml version="1.0" encoding="UTF-8"?>
<title>Pakketservice Belgiƫ</title>

and reading the xml with the folowing code,

DocumentBuilderFactory dbfact = DocumentBuilderFactory.newInstance();
DocumentBuilder dbuild = dbfact.newDocumentBuilder();
String path = application.getRealPath("/")+"XMLs/Locations.xml";
Document dc = dbuild.parse (new File(path));

and, i am getting the following error message Invalid byte 2 of 3-byte UTF-8 sequence.
at Source)
at Source)
at Source)
at Source)
at$ Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at org.apache.jsp.locations_jsp._jspService(
at org.apache.jasper.runtime.HttpJspBase.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.jasper.servlet.JspServletWrapper.service(
at org.apache.jasper.servlet.JspServlet.serviceJspFile(
at org.apache.jasper.servlet.JspServlet.service(
at javax.servlet.http.HttpServlet.service(
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
at org.apache.catalina.core.ApplicationFilterChain.doFilter(
at org.apache.catalina.core.StandardWrapperValve.invoke(
at org.apache.catalina.core.StandardContextValve.invoke(
at org.apache.catalina.core.StandardHostValve.invoke(
at org.apache.catalina.valves.ErrorReportValve.invoke(
at org.apache.catalina.core.StandardEngineValve.invoke(
at org.apache.catalina.connector.CoyoteAdapter.service(
at org.apache.coyote.http11.Http11Processor.process(
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(
at org.apache.tomcat.util.threads.ThreadPool$
at Source)


The online solutions are not specific.

some body suggested me to use the following encoding format,

<?xml version="1.0" encoding="ISO-8859-1"?>

but this also not working..... Can anybody help me in this regard, hw to resolve the issue...?
David Newton

Joined: Sep 29, 2008
Posts: 12617

This isn't a Struts question--you'd have better luck asking on a more appropriate forum.
I agree. Here's the link:
subject: How to resolve "MalformedByteSequenceException: Invalid"
It's not a secret anymore!