File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

downloading zip files from a site to local disk(urgent please)

 
Dinesh Jayaraj
Greenhorn
Posts: 23
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends:
iam doing a project in java networking.
iam connecting to a site(http or ftp) having userid and password.
code for this is given below,and i want to download the
files in that site to the local disk, but that site contains zip file,i want to download that zip file as it is to the local disk creating a file folder in the local disk.
how it can be done?
help urgently please
import java.io.*;
import java.net.*;
class zipfold
{
public static void main(String args[])
{
String url=null;
String userid=null;
String passwd=null;

try
{
BufferedReader bo=new BufferedReader(new InputStreamReader(System.in));
System.out.println("entet the userid");
userid=bo.readLine();
System.out.println("entet the password");
passwd=bo.readLine();
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);
InputStream content = (InputStream)uc.getInputStream();
BufferedReader in = new BufferedReader (new InputStreamReader (content));
String line;
FileOutputStream fo=new FileOutputStream("c:/dinesh1/springer.html");
while ((line = in.readLine()) != null) {
System.out.println (line);
byte b[]=new byte[line.length()];
b=line.getBytes();
fo.write(b);
}
}catch(Exception e){System.out.println(e);}
} //function main
} //class

------------------
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Holmes was kind enough to donate an ftp client implementation using sockets. This should meet your needs.
Hope this helps
 
Eric Lafargue
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can try the FtpBean component at the following address.
I used it already it it works perfectly.
www.geocities.com/SiliconValley/Code/9129/javabean/ftpbean
Eric
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic