public int copyfile(String filesToTransfor[]) {
int oneChar, count = 0;
if (filesToTransfor.length < 1) {
System.err.println("Two file path is required to complete the process");
System.exit(1);
}
try {
URL url = new URL(filesToTransfor[0]);
System.out.println("Opening connection to " + filesToTransfor[0] + "...");
URLConnection urlC = url.openConnection();
// Copy resource to local file, use remote file
// if no local file name specified
InputStream is = url.openStream();
// Print info about resource
System.out
.println("Copying resource (type: " + urlC.getContentType());
// Date date=new Date(urlC.getLastModified());
// System.out.println(", salesnet file modified on: " + date.toString() + ")...");
System.out.flush();
FileOutputStream fos = null;
if (filesToTransfor.length < 2) {
String localFile = null;
// Get only file name
StringTokenizer st = new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
localFile = st.nextToken();
fos = new FileOutputStream(localFile);
} else
fos = new FileOutputStream(
while ((oneChar = is.read()) != -1) {
fos.write(oneChar);
count++;
}
is.close();
fos.close();
System.out.println(count + " byte(s) copied");
} catch (MalformedURLException e) {
System.err.println(e.toString(
} catch (IOException e) {
System.err.println(e.toString(
}
return count;
}
A self-motivated, multi-domain, hardworking, responsible and solutions-orientated JAVA, J2EE, Spring 4, HTML 5, CSS 3, JavaScript, ES6, Typescript, AngularJS 1.4, jQuery 1.8, PHP 5, Shell Script, PL SQL, MySQL, Google App Engine, Google Datastore, JPA, Cucumber BDD Professional with more then 8+ Years of IT experience in a various IT stages including Design, developing, Unit testing and enhancement and 24*7 support application.
Configure HTML/JavaScript
Friday, November 12, 2010
file copy from url in java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment