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
------------------