Downloading a File program in java


Objective:
            To Download A Particular File From the Internet or from the  Local Host .

Packages used:
java.net.*                     : Provides the classes for implementing networking applications.
java.io.*                       : Provides for system input and output through data streams, serialization and the file system.

Classes used:
URL                : Class URL represents a Uniform Resource Locator, a pointer to a "resource" on the World Wide Web. A resource can be something as simple as a file or a directory, or it can be a reference to a more complicated object, such as a query to a database or to a search engine. URL can be broken into several parts like protocol,machine name,port number,host name and file name.
InputStream      : abstract class is the superclass of all classes representing an input stream of bytes. Abstract class for reading from character streams.
OutputStream    : abstract class is the superclass of all classes representing an output stream of bytes. An output stream accepts output bytes and sends them to some sink. Abstract class for writing to character streams
  
 Logical flow of the program:
·         The file names are obtained as a command line argument.
·         If the file names are not given as an argument an error message is generated,else the contents of the object of InputStream is defined to accept read the file.
·         The contents of the file is displayed.
·         If the file name is specified to which the previous file should be copied , then the contents of the file are copied to that file.

Important notes:
·         While doing the program in networking the program must import the package “java.net.*”.
·         Since the program is accessing files,the main() method should throw Exception.





0 comments:

Copyright © 2012 OpenTechZone | Kesari Technologies |