File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Chaining readers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Chaining readers" Watch "Chaining readers" New topic
Author

Chaining readers

Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 43
I've been playing with reading a gzip'd file.

This works fine:

Two questions:

1. Is the approach I pieced together from various websites the best/most elegant way to read text from a gzip'd file?

2. There are two streams and a reader. Which of the streams/reader should I close when I'm done reading the file. All of them?

Thanks very much.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4490
    
    8

1. I think you've got one more reader than you need there. You should be able to pass fstream straight into the InputStreamReader - I don't see any need to introduce a DataInputStream. Other than that, it looks fine.

2. Close the outer one (your BufferedReader) and that will cascade down - it will close all of them.
Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 43
Matthew Brown wrote:1. I think you've got one more reader than you need there. You should be able to pass fstream straight into the InputStreamReader - I don't see any need to introduce a DataInputStream. Other than that, it looks fine.

2. Close the outer one (your BufferedReader) and that will cascade down - it will close all of them.

Excellent. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chaining readers