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... 4 12033
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...
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...
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: bmgz |
last post by:
I am having problems trying to use the gzip module, I do the followig
>>>import gzip
>>>file = gzip.GzipFile("testfile.txt")
>>>file.write() -which params does this accept?, archive name?
I get this ERROR:
Traceback (most recent call last):
File "<stdin>", line 1, in ?
|
by: Xah Lee |
last post by:
today i need to use Python to decompress gzip files.
since i'm familiar with Python doc and have 10 years of computing
experience with 4 years in unix admin and perl, i have quickly located
the official doc:
http://python.org/doc/2.4.1/lib/module-gzip.html
but after a minute of scanning, please someone tell me what the fuck is
it...
|
by: Xah Lee |
last post by:
Python Doc Problem Example: gzip
Xah Lee, 20050831
Today i need to use Python to compress/decompress gzip files. Since
i've read the official Python tutorial 8 months ago, have spent 30
minutes with Python 3 times a week since, have 14 years of computing
experience, 8 years in mathematical computing and 4 years in unix admin
and perl, i...
|
by: Bill |
last post by:
I've written a small program that, in part, reads in a file and parses
it. Sometimes, the file is gzipped. The code that I use to get the
file object is like so:
if filename.endswith(".gz"):
file = GzipFile(filename)
else:
file = open(filename)
Then I parse the contents of the file in the usual way (for line in
|
by: benjamin.grant |
last post by:
can configure, make and install
everything fine. I'm using python 2.4 I have ubuntu dapper drake. I am
trying to install hplip which requires python. When I do this, this
also works but while running the following error occurs:
Traceback (most recent call last):
File "/usr/local/bin/hp-setup", line 31, in ?
import readline, gzip...
| |
by: Nader |
last post by:
Hello,
I have a gzip file and I try to read from this file withe the next
statements:
gunziped_file = gzip.GzipFile('gzip-file')
input_file = open(gunziped_file,'r')
But I get the nezt error message:
|
by: Sean Davis |
last post by:
I have a large file that I would like to transform and then feed to a
function (psycopg2 copy_from) that expects a file-like object (needs
read and readline methods).
I have a class like so:
class GeneInfo():
def __init__(self):
#urllib.urlretrieve('ftp://ftp.ncbi.nih.gov/gene/DATA/
gene_info.gz',"/tmp/gene_info.gz")
|
by: Gabriel Genellina |
last post by:
En Wed, 19 Nov 2008 13:25:03 -0200, Barak, Ron <Ron.Barak@lsi.com>
escribió:
Note *where* the exception is raised. Until something is actually read, no
check is made for the file format.
--
Gabriel Genellina
|
by: Barak, Ron |
last post by:
Thanks Gabriel,
Okay, I get it: I was under the impression that the format check would be done on the open.
Bye,
Ron.
-----Original Message-----
From: Gabriel Genellina
Sent: Thursday, November 20, 2008 02:06
To: python-list@python.org
Subject: Re: Why is try...except in my code not working (gzip/text files) ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |