• Post Reply Bookmark Topic Watch Topic
  • New Topic

problem in using zipinputstream class  RSS feed

 
Dinesh Jayaraj
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
os:windows95
application:jdk1.3
hi everybody:
here is a code written to connect to a password protected url and
also to see the contents of that site.
the url listed in the code contains a zip file(content type application/x-gzip)
i have connected to that site through URLConnection class and created a
ZipInputStream to print name of each zipEntry in that file but the program only
prints the content type and content length and comes out it doesnt print
the list of files in that zip archive.
please any body help me
(if u want to connect to that site
for verification please type this url in the address bar of u r browser http://fdg852dp:wxx853dq@link.springer.de/customer/service/mirr/tocs/2000-10-16-tocs.tar.gz)
thanks in advance
dinesh

import java.io.*;
import java.net.*;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipEntry;
class zipfoldt
{
public zipfoldt()
{}
public static void main(String args[])
{
String url="http://link.springer.de/customer/service/mirr/tocs/2000-10-16-tocs.tar.gz";
String userid="fdg852dp";
String passwd="wxx853dq";

try
{
/* BufferedReader bo=new BufferedReader(new InputStreamReader(System.in));
System.out.println("entet the url");
url=bo.readLine(); */
URL u=new URL(url);
String compress= userid+":"+passwd;
String encoding=new sun.misc.BASE64Encoder().encode(compress.getBytes());
URLConnection uc= u.openConnection();
uc.setRequestProperty("Authorization","Basic "+encoding);
uc.connect();
InputStream in1= (InputStream)uc.getInputStream();
System.out.println(uc.getContentType());
int length=uc.getContentLength();
System.out.println(length);
ZipInputStream in=new ZipInputStream(in1);
ZipEntry zip;
/* getNextEntry() method reads the next ZIP file entry and
positions stream at the beginning of the entry data and returns
zipEntry */
while((zip=in.getNextEntry())!=null)
{
System.out.println(zip.getName());
System.out.println(zip.getSize());
in.closeEntry();
}
}catch(Exception e){System.out.println(e);}
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!