Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners How to copy files from one folder to another based on lastmodified date
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Manoj
How to copy files from one folder to another based on lastmodified date
1 Answer(s)      6 years and 8 months ago
Posted in : Java Beginners


I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.


Advertisement
View Answers

April 14, 2008 at 7:54 PM


hi

import java.io.*;

public class CopyFile{
private static void copyfile(String srFile, String dtFile){
try{
File f1 = new File(srFile);

File f2 = new File(dtFile);

InputStream in = new FileInputStream(f1);
//For Append the file.
// OutputStream out = new FileOutputStream(f2,true);

//For Overwrite the file.
OutputStream out = new FileOutputStream(f2);


byte[] buf = new byte[1024];

int len;

while ((len = in.read(buf)) > 0){

out.write(buf, 0, len);

}

in.close();

out.close();

System.out.println("File copied.");

}

catch(FileNotFoundException ex){
System.out.println(ex.getMessage() + " in the specified directory.");

System.exit(0);

}

catch(IOException e){

System.out.println(e.getMessage());

}

}

public static void main(String[] args){

switch(args.length){

case 0: System.out.println("File has not mentioned.");

System.exit(0);

case 1: System.out.println("Destination file has not mentioned.");

System.exit(0);

case 2: copyfile(args[0],args[1]);

System.exit(0);

default : System.out.println("Multiple files are not allow.");

System.exit(0);

}

}

}

-----------------------

read for more information.

http://www.roseindia.net/java/


Related Tutorials/Questions & Answers:
How to copy files from one folder to another based on lastmodified date - Java Beginners
Copy files from one folder to another  How to copy files from one folder to another based on lastmodified date
How to copy files from one folder to another based on lastmodified date - Java Beginners
How to copy files from one folder to another based on lastmodified date  I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.  hiimport
Advertisements
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  How to copy an image from one folder to another folder using jsp
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want... copy from one directory to another in java. Thanks
How to copy an jpeg image from one folder to other folder using jsp
How to copy an jpeg image from one folder to other folder using jsp  hello, i am creating photo gallery where from admin side i allow admin to browse... be in my image folder...so,How to copy an jpeg image from one folder to other
how to write function of copy from one to another location in this code
how to write function of copy from one to another location in this code  I need to write a code to copy a file from one location to another using... to add code for copy using swing!! thanks in advance.** /* For Browse button
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another... from a directory to another directory. How to achieve this? Is there any API
Copy data from one JTextField to another JTextField
, you will learn how to copy the data from one JTextField into another... Copy data from one JTextField to another JTextField... data into first JTextfield and select the entered text, right click, copy
File copy from one drive to another. - Java Beginners
File copy from one drive to another.  I want to copy a .mp3 file from one drive(let d: drive)to another drive(let e: drive) in my Windows XP. How can I do
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy xml files from one folder to another my source file contains the field filename wich contains the file to be copied. I want to copy the file from
Copy one file into another
Copy one file into another In this section, you will learn how to copy content of one file into another file. We will perform this operation by using...;This string is copied from one file to another\n"); bf.close(); InputStream
i want to copy files from one machine to other using java and the code will be running on third machine
i want to copy files from one machine to other using java and the code will be running on third machine  i want to copy some files from one machine... machine say 'c'. So , can you help me on this that how can i do this using
How to copy many files into one file and how to manage the content of the final file?
How to copy many files into one file and how to manage the content of the final... in a folder and paste it into one file. My following code is working but the problem is for example if i have three txt files my program copy the content
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi! This is Prasad Jandrajupalli. I have the 3 JSP's, but I want communicate with each... is not communicate with the Third JSP. I want forward the control from first jsp to second
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning... string from one class to another. import java.util.*; class A{ static String... string from one class to another. import java.io.*; class Class1 { public
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my...; <from-view-id>/JSF/UserDetail.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <
swings:how to link from one form to another form
swings:how to link from one form to another form  how to link from one form to another form
Copy One Database Table to Another
Copy One Database Table to Another   ... to another database table. That means we copy one table to a different table...;java CopyOneDatabaseTableToAnother Copy data from one database table
how to backup files and folder with Java
how to backup files and folder with Java  Does anyone know to create a backup with java?. backup files and folders from my computer to an external...:\\Documents and Settings\\bharat\\Desktop\\bipul\\New Folder\\TableExample.java
java program to take the backup of folders and copy the folder in different location without deleting the existing one
the backup of folders and copy the folder in different location without deleting the existing one   Have a look at the following link: Java Copy one folder...java program to take the backup of folders and copy the folder in different
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
Java - Copying one file to another
;    This example illustrates how to copy contents from one... the contents from one specified file to another specified file. copyfile(String... to another specified file from the first one specified file. // For creating a byte
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...; } } //Another class Class2. public class Class2 { public static void main(String
how to read 100 text files from a folder or directory and write the data into a single file.using java programming?
how to read 100 text files from a folder or directory and write the data... two columns the same as in the 100 files..and the data is to be writen from 3rd... files which has data in the form of intgers consisting of 3 columns and app..3000
Copying an array to another
Copying an array to another       Java Copy Array Example:In this tutorial, you will learn how to copy data from one array to another. Here, providing you an example with code
how to go from one frame to another frame in swings - Java Beginners
how to go from one frame to another frame in swings  Hi, My task is to go from one frame to another.......... let us think that iam having two... this task in swings or applet......... i have gone through one example of login
How To Pass data from one GUI to another in java swing
How To Pass data from one GUI to another in java swing  I'm new to java and part of our assignment is to build a GUI and display a result set from data input. I'm stuck at how to get the user's input from JTextFields and combobox
how to download a file from a folder??
how to download a file from a folder??  i can upload any kind of files to a folder, and only the path of the file is saved into the database, now how a client can download the file from my folder. pls provide me the jsp code
how to use one form out of multiple form from one jsp to another jsp
how to use one form out of multiple form from one jsp to another jsp  Hi All. please give me your valuable advise for below requirement.. I have... one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise
How to copy a file in java
How to copy a file in java In this section you will learn about how to copy a content of one file to another file. In java, File API will not provide any direct way to copy a  file.  What we can do is, read a content of one
 

 

 

DMCA.com