This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes Strange behaviour of SequenceInputStream with UTF-16 Encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Strange behaviour of SequenceInputStream with UTF-16 Encoding" Watch "Strange behaviour of SequenceInputStream with UTF-16 Encoding" New topic
Author

Strange behaviour of SequenceInputStream with UTF-16 Encoding

cohen schingis
Greenhorn

Joined: Oct 12, 2012
Posts: 1
I tried to create a SequenceStream of UTF-16 encoded files.




if i run this i got this as output:



if i run it, with only one File it works fine:



output:



Where are the Questionsmarks from? how can i handle this?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19686
    
  10

Welcome to the Ranch, cohen!

It looks to me like the last line in each of the files doesn't have a line-ending character, so when you concatenate the three files, the last line of File 1 and the first line of File 2 look like one line of text. That would at least explain why they are combined that way.

As for the question mark, it looks to me like each of the file has some bytes at the end which (as we already saw) aren't line-endings, but instead are some other character which can't be represented as text.

I would suggest you look at the files to see what's actually happening. A hex editor might be better than an ordinary text editor to do that, since the text editor might hide the file trailer character from you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Strange behaviour of SequenceInputStream with UTF-16 Encoding
 
jQuery in Action, 3rd edition