InputStream - invalid byte 1 of 1-byte UTF-8 sequence

A

Arun

I am using

InputStream input = new ByteArrayInputStream( fileContents.getBytes()
);

to get an input using the string, filecontents.

However the input doesnt read properly, and when i try to parse it,i
get the error invalid byte 1 of 1-byte UTF-8 sequence.

I do know that the file contains that square symbol in it.
I am pretty confident that this byte is what's making the parsing mess
up.

Anyone know how to get around this? Like a method of removing all those
'square bytes'?
 
M

Michael Borgwardt

Arun said:
I am using

InputStream input = new ByteArrayInputStream( fileContents.getBytes()
);

to get an input using the string, filecontents.

However the input doesnt read properly,

What does that mean? What code? Does it throw a DoesntReadProperlyException?

and when i try to parse it,i
How?

get the error invalid byte 1 of 1-byte UTF-8 sequence.

Sounds like you're using a wrong encoding at one point. But if you're going
to treat it as text data anyway, why first convert it into bytes? Why not
use a StringReader?
 
W

William Brogden

I am using

InputStream input = new ByteArrayInputStream( fileContents.getBytes()
);

to get an input using the string, filecontents.

However the input doesnt read properly, and when i try to parse it,i
get the error invalid byte 1 of 1-byte UTF-8 sequence.

I do know that the file contains that square symbol in it.
I am pretty confident that this byte is what's making the parsing mess
up.

You see that symbol because your system has no character to show that
matches. A programmer's editor (I use UltraEdit-32) with hex display
capability would help you figure out whats happening. If that file
originated as a MS Word document, it may be one of those "smart"
punctuation marks that is not a valid Unicode character.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,928
Messages
2,570,068
Members
46,513
Latest member
JacklynMcC

Latest Threads

Top