source file name:  DownloadFileDemo.java


import java.io.*;  

import java.net.*;  

 class DownloadFileDemo

{  

public static void main(String[] dbj)

{  

InputStream in=null;

OutputStream out=null;

try

{  

URL url=new URL(dbj[0]);

in=url.openStream();

if(dbj.length==2)

out=new FileOutputStream(dbj[1]);

else

out=System.out;


byte[] buffer=new byte[1024];

int bt_read;

while((bt_read=in.read(buffer))!=-1)

{

out.write(buffer,0,bt_read);

}

}

catch(Exception e)

{System.out.println(e);}  

finally

{

try

{

in.close();

out.close();

}

catch(Exception e)

{System.out.println(e);}  

}

}  

}  

output 1:

D:\JavaPrograms\Networking>javac DownloadFileDemo.java

D:\JavaPrograms\Networking>java DownloadFileDemo https://sjnprogramming.blogspot.com/ p/about.html about1.html

about,html file copy from internet and store on disk about1.html

output 2:

down file from local machine display on console.

D:\JavaPrograms\Networking>java DownloadFileDemo file:\\\JavaPrograms\\Networking\ \InetAddressDemo.java

import java.io.*;

import java.net.*;

 class InetAddressDemo

{

public static void main(String[] args)

{

try

{

InetAddress ip1=InetAddress.getByName("sjnprogramming.blogspot.com");

InetAddress ip2=InetAddress.getLocalHost();

InetAddress[] ip=InetAddress.getAllByName("www.yahoo.com");

System.out.println("Host Name: "+ip1.getHostName());

System.out.println("IP Address: "+ip1.getHostAddress());

System.out.println("IP Address of local computer: "+ip2);

System.out.println("IP Addresses of ");

for(int i=0;i<ip.length;i++)

System.out.println(ip[i]);

}

catch(Exception e)

{System.out.println(e);}

}

}

D:\JavaPrograms\Networking>