The urlconnection class of Java provides the rul connection function. I can test the HTTP connection,
You may also be able to connect to FTP and Other types. Further test is required.
After obtaining the connection, you can obtain inputstream from The RUL connection, so that you can use the read method of inputstream to read the file.
Example:
Public static Boolean httpdownload (string httpurl, string SaveFile ){
// Download the Network File
Int bytesum = 0;
Int byteread = 0;
URL url = NULL;
Try {
Url = new URL (httpurl );
} Catch (malformedurlexception E1 ){
// Todo auto-generated Catch Block
E1.printstacktrace ();
Return false;
}
Try {
Urlconnection conn = URL. openconnection ();
Inputstream instream = conn. getinputstream ();
Fileoutputstream FS = new fileoutputstream (SaveFile );
Byte [] buffer = new byte [1204];
While (byteread = instream. Read (buffer ))! =-1 ){
Bytesum + = byteread;
// System. Out. println (bytesum );
FS. Write (buffer, 0, byteread );
}
Return true;
} Catch (filenotfoundexception e ){
E. printstacktrace ();
Return false;
} Catch (ioexception e ){
E. printstacktrace ();
Return false;
}
}