[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

java.lang.Exception: sun.io.MalformedInputException

Posted on 2014-04-17
5
Medium Priority
?
1,478 Views
Last Modified: 2014-04-17
Hi,
   I am trying to read an html file which is in French from buffer reader and I am getting java.lang.Exception: sun.io.MalformedInputException. I am attaching the html file and java code which reads the file. Please let me know what is going wrong here.

THank you

Below is the HTML code
<!DOCTYPE html SYSTEM  "xhtml1-transitional.dtd">
<html>
<head>
<title>Council Template</title>
</head>
<body>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h2>RÈGLEMENTS</h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h2></h2>
<h1>CHEVALIERS DE COLOMB</h1>
<h2></h2>
<h2></h2>
<br/>

<br />
</body>
</html>


and java code is

InputStream ins = PdfUtil.class.getResourceAsStream(htmlFile);

            

            Reader in = new InputStreamReader(ins, "UTF-8");
            BufferedReader br = new BufferedReader(in);
            String linetext = br.readLine();
            while (linetext != null) {
                  // Convert Line Code
                  if (linetext.indexOf("<%") > 0) {
                        if (!isLoop) {
                              isLoop = true;
                              forLoop = new ForLoop(linetext);
                              linetext = null;
                        } else {
                              linetext = forLoop.generateLoop().toString();
                              isLoop = false;
                        }
                  }
                  if (isLoop)
                        forLoop.add(linetext);
                  else
                        newHtmlFile.append(linetext);
                  linetext = br.readLine();
            }
            br.close();


I am getting below exception at br.readLine()
java.lang.Exception: sun.io.MalformedInputException
Caused by: sun.io.MalformedInputException: null
at sun.io.ByteToCharUTF8.convert(ByteToCharUTF8.java:278) ~[na:1.5.0]
at sun.nio.cs.StreamDecoder$ConverterSD.convertInto(StreamDecoder.java:316) ~[na:1.5.0]
at sun.nio.cs.StreamDecoder$ConverterSD.implRead(StreamDecoder.java:366) ~[na:1.5.0]
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:252) ~[na:1.5.0]
at java.io.InputStreamReader.read(InputStreamReader.java:212) ~[na:1.5.0]
at java.io.BufferedReader.fill(BufferedReader.java:157) ~[na:1.5.0]
at java.io.BufferedReader.readLine(BufferedReader.java:320) ~[na:1.5.0]
at java.io.BufferedReader.readLine(BufferedReader.java:383) ~[na:1.5.0]
0
Comment
Question by:Sthokala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 16

Expert Comment

by:Valeri
ID: 40006581
instead of
Reader in = new InputStreamReader(ins, "UTF-8");
try with:
Reader in = new InputStreamReader(ins);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 40006619
It's probably not UTF-8. You need to read it with the same encoding as was used to write it.
0
 

Author Comment

by:Sthokala
ID: 40006625
Hello,
  Thank yuo for your reply. Now the system is not throwing error, but I am getting ? in place of È.

Thank you
0
 
LVL 16

Accepted Solution

by:
Valeri earned 1500 total points
ID: 40006638
what do you get instead of È ?

what about this:
Reader in = new InputStreamReader(ins, Charset.forName("ISO-8859-1"));
0
 
LVL 16

Expert Comment

by:Valeri
ID: 40006647
how do you get this file? if it is with http request, then the charset is presented in the header.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question