• Post Reply Bookmark Topic Watch Topic
  • New Topic

Elliot Harold I/O problem  RSS feed

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Please help...already well googled! (New to java.)

Going through said book, stuck on chapter 6....FileDumper2 program.

Would someone please download and try to compile these (link below):

1. FileDumper2
2. HexFilter
3. DecimalFilter
4. DumpFilter
5. BufferedStreamCopier from Chapter 6 (6.4)

They will compile but am getting ArrayIndexOutOfBoundsException when try to run Hex and Decimal (ASCII runs ok).
Just cannot see it.
Problem in the fill() method methinks......fill() calls read() calls fill()......

Thanks in advance.

(http://www.cafeaulait.org/books/javaio2/ioexamples/06/index.html)

C:\Users\john\Desktop\CODE>java FileDumper2 -d FileThree.txt
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at com.elharo.io.DumpFilter.read(DumpFilter.java:26)
at com.elharo.io.DumpFilter.read(DumpFilter.java:53)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at com.elharo.io.BufferedStreamCopier.copy(BufferedStreamCopier.java:23)
at FileDumper2.dump(FileDumper2.java:54)
at FileDumper2.main(FileDumper2.java:29)


C:\Users\john\Desktop\CODE>java FileDumper2 -a FileThree.txt
This is a test.
C:\Users\john\Desktop\CODE>
 
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

Can you please supply
a) the exception stack trace
b) the input you're giving

I've just tried it (after making the buffer and index fields of DumpFilter non-private to get it to compile) and it's working just fine.
 
Sean Mac Eoin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help,

Instead of making the variables non-private I copied them into HexFilter and DecimalFilter files and it all compiled ok (obviously stupid ...since its a different array and variable ), maybe that's where the problem is.

If I make them public instead perhaps they will run.

Will try it.

Thanks
 
Sean Mac Eoin
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Worked !

Thanks.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!