File-Download program in java


import java.io.*;
import java.net.*;

public class FileDownload
{
     public static void main(String[] args)
      {
          try
          {
                        URL u=new URL("http://www.yahoomail.com/index.html");
                        InputStream is=u.openStream();
                        InputStreamReader isr=new InputStreamReader(is);
                        BufferedReader br=new BufferedReader(isr);

                        String s=null;
                        do
                        {
                                    s=br.readLine();
                                    System.out.println(s);
                        }while(s!=null);
           }catch(Exception e)
             {
                                System.out.println(e);
             }
       }//close main
}//close class









*       File-Download1

import java.io.*;
import java.net.*;

public class FDownload
{
     public static void main(String[] args)
      {
          try
          {
            URL u=new URL("http://www.rediffmail.com/index.html");
            FileWriter fw = new FileWriter("copy.html");
           
           
            InputStream is=u.openStream();
            InputStreamReader isr=new InputStreamReader(is);
            BufferedReader br=new BufferedReader(isr);

            String s=br.readLine();
            while(s != null)
            {
                s=br.readLine();
                fw.write(s);
            }
           }catch(Exception e)
             {
            System.out.println(e);
             }
       }//close main
}//close class

0 comments:

Copyright © 2012 OpenTechZone | Kesari Technologies |