• Post Reply Bookmark Topic Watch Topic
  • New Topic

ByteArrayInputStream problem

 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I was trying to code this simple ByteArrayInput/OutputStream question.
Code works properly except for a small problem.
Code:


Output
D:\Education\Java\JavaStudyRoom\FileIO>javac ByteEx.java

D:\Education\Java\JavaStudyRoom\FileIO>java -cp . ByteEx
I am enjoying this.?
Value: I am enjoying this.
I am enjoying this.


The output is according to my expectation. Even ByteArrEx.txt also gets created with correct content. However I dont understand why does ? appear in the 1st line of output ie in this :
I am enjoying this.?

Please tell me what could be the reason and how do I eliminate this?

Thanks
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to I/O and Streams.
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this, it should explain whats happening:


 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ooh, good call. I missed that one.
 
Kaustubh G Sharma
Ranch Hand
Posts: 1283
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you must declare some value to integer i may be 0 or -1

hope this will work for you..


kaustubh
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D. Ogranos wrote:Try this, it should explain whats happening:




Oh yes it did explain everything.
I dint knew -1 is interpreted as "?".
I replaced if(c==-1) with if(i==-1) and everything works fine now.

Thanks for bringing this to my notice.

Suvojit
 
Rob Spoor
Sheriff
Posts: 20819
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(char)-1 is the same as (char)65535. While a valid character most systems, especially consoles, are unable to display it. Consoles even have problems with anything that isn't ASCII, like é.
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:(char)-1 is the same as (char)65535. While a valid character most systems, especially consoles, are unable to display it. Consoles even have problems with anything that isn't ASCII, like é.


Thats a precious piece of information.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!