469,352 Members | 1,708 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

readLine() for a gzip file

At present I use the following to read a text file
...
private BufferedReader in = null;
...
try {
in = new BufferedReader(new FileReader(Filename));
while((line = in.readLine()) != null) {
// work
}

I would like to gzip the input file, how do I change my code
to read a gzipped text file? From the Sun tutorial I only saw
how to read a given number of bytes, but I want to read lines.

Any help appreciated.
tnx, Phil...
Jul 17 '05 #1
4 11574
How in the hell are you going to read lines from a zipped file? what the
hell
is wrong with this news group, are all you people smoking crack or what?
I've never seen such an endless stream of absolutely dumbass questions
as those that for some reason or another end up being defecated onto
this group.

Angry post to follow.
"Phil" <ry***@ieee.org> wrote in message
news:lczZa.80417$Oz4.20213@rwcrnsc54...
At present I use the following to read a text file
...
private BufferedReader in = null;
...
try {
in = new BufferedReader(new FileReader(Filename));
while((line = in.readLine()) != null) {
// work
}

I would like to gzip the input file, how do I change my code
to read a gzipped text file? From the Sun tutorial I only saw
how to read a given number of bytes, but I want to read lines.

Any help appreciated.
tnx, Phil...
Jul 17 '05 #2
The class GZIPInputStream in the package java.util.zip
is supposed to do the decompression for you automatically.
I just want to read it line by line instead of a buffer of bytes.

"dfdfd" <df**@aol.com> wrote in message news:DpzZa.12283$ug.11789@lakeread01...
How in the hell are you going to read lines from a zipped file? what the
hell
is wrong with this news group, are all you people smoking crack or what?
I've never seen such an endless stream of absolutely dumbass questions
as those that for some reason or another end up being defecated onto
this group.

Angry post to follow.
"Phil" <ry***@ieee.org> wrote in message
news:lczZa.80417$Oz4.20213@rwcrnsc54...
At present I use the following to read a text file
...
private BufferedReader in = null;
...
try {
in = new BufferedReader(new FileReader(Filename));
while((line = in.readLine()) != null) {
// work
}

I would like to gzip the input file, how do I change my code
to read a gzipped text file? From the Sun tutorial I only saw
how to read a given number of bytes, but I want to read lines.

Any help appreciated.
tnx, Phil...

Jul 17 '05 #3
Phil <ry***@ieee.org> wrote:
The class GZIPInputStream in the package java.util.zip
is supposed to do the decompression for you automatically.
I just want to read it line by line instead of a buffer of bytes.


whoa... since we are in Java land... Let's get the terms right. There's
a difference between bytes and characters. When you use Reader/Writer,
you're dealing with characters, and when you use InputStream and
OutputStream, you're dealing with bytes.

I presume you mean characters and not bytes. You probably want to wrap
the the FileReader with

[angry stuff snipped]

As you have noticed there's no gzip reader, but you do have gzip
inputstream. One can cross from the world of inputstream to the reader
world by using the InputStreamReader. Here's what I'd do:

BufferedReader reader = new BufferedReader(
new InputStreamReader(
new GZIPInputStream(
new FileInputStream( filename.gz ) ) ) );

You may run into problems if you're dealing with multi byte characters
....

Pedro

"Phil" <ry***@ieee.org> wrote in message
news:lczZa.80417$Oz4.20213@rwcrnsc54...
At present I use the following to read a text file
...
private BufferedReader in = null;
...
try {
in = new BufferedReader(new FileReader(Filename));
while((line = in.readLine()) != null) {
// work
}

I would like to gzip the input file, how do I change my code
to read a gzipped text file? From the Sun tutorial I only saw
how to read a given number of bytes, but I want to read lines.

--
Caution: breathing may be hazardous to your health.
Jul 17 '05 #4
Pedro,
Thanks a bunch, I tried your suggestion exactly and it worked the first time!!!
Phil...

"Pedro Sam" <p2***@uwaterloo.ca> wrote in message news:bh**********@tabloid.uwaterloo.ca...
Phil <ry***@ieee.org> wrote:
The class GZIPInputStream in the package java.util.zip
is supposed to do the decompression for you automatically.
I just want to read it line by line instead of a buffer of bytes.


whoa... since we are in Java land... Let's get the terms right. There's
a difference between bytes and characters. When you use Reader/Writer,
you're dealing with characters, and when you use InputStream and
OutputStream, you're dealing with bytes.

I presume you mean characters and not bytes. You probably want to wrap
the the FileReader with

[angry stuff snipped]

As you have noticed there's no gzip reader, but you do have gzip
inputstream. One can cross from the world of inputstream to the reader
world by using the InputStreamReader. Here's what I'd do:

BufferedReader reader = new BufferedReader(
new InputStreamReader(
new GZIPInputStream(
new FileInputStream( filename.gz ) ) ) );

You may run into problems if you're dealing with multi byte characters
...

Pedro

"Phil" <ry***@ieee.org> wrote in message
news:lczZa.80417$Oz4.20213@rwcrnsc54...
At present I use the following to read a text file
...
private BufferedReader in = null;
...
try {
in = new BufferedReader(new FileReader(Filename));
while((line = in.readLine()) != null) {
// work
}

I would like to gzip the input file, how do I change my code
to read a gzipped text file? From the Sun tutorial I only saw
how to read a given number of bytes, but I want to read lines.



--
Caution: breathing may be hazardous to your health.

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by bmgz | last post: by
10 posts views Thread by Xah Lee | last post: by
14 posts views Thread by Bill | last post: by
reply views Thread by benjamin.grant | last post: by
1 post views Thread by Nader | last post: by
6 posts views Thread by Sean Davis | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.