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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 35
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: 4343
    
    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: 35
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Chaining readers
 
Similar Threads
Check for duplicates in database before insert
to read lines inside brackets
class that prints its own source code
Problem with reading txt file into 2d array
Comparing contents of a file with String[]