I have to make a simple utility to copy files from a folder to another folder in the same hierarchy, without overwriting the existing.
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:
Advertisements
File copy from one directory to another in javaFile
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 file from folder to folder - Java Beginnerscopy 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 anotherCopy 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
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 anotherhow 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 pass variable from one class to another in javaHow 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
Copy One Database Table to Another
Copy data
from one database table to
another!
4 row(s)affected...
Copy One Database Table to
Another
... to
another database table. That means we
copy one table to a different table
How To Pass data from one GUI to another in java swingHow 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
Java - Copying one file to another;
This example illustrates
how to
copy contents
from one... which copies the contents
from one specified file to
another specified file... for buffering the contents of
one file and
write to
another specified file
from how to backup files and folder with Javahow 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
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 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
update one table from another tableupdate
one table
from another table hello, i need to update
one table fields by using
another table fields. I have to tables Products.... for example TotalQuantity field
from Products table should be updated if i
copying data from one table to anothercopying data
from one table to another i need to
copy data
from one table to
another table..
i.e the 1st eid of employee table must be copied to the 1st eid in appusers table, 2nd eid of employee to the 2nd eid of appusers
how to search a text in all files in a folder in unixhow to search a text in all
files in a
folder in unix Hi,
I am using ubuntu and my need is to find all the
files containing a text say "India".
How... terminal to find a text in all the
files in all directories?
how to search
how to search a text in all files in a folder in unixhow to search a text in all
files in a
folder in unix Hi,
I am using ubuntu and my need is to find all the
files containing a text say "India".
How... terminal to find a text in all the
files in all directories?
how to search
how to search a text in all files in a folder in unixhow to search a text in all
files in a
folder in unix Hi,
I am using ubuntu and my need is to find all the
files containing a text say "India".
How... terminal to find a text in all the
files in all directories?
how to search
how to search a text in all files in a folder in unixhow to search a text in all
files in a
folder in unix Hi,
I am using ubuntu and my need is to find all the
files containing a text say "India".
How... terminal to find a text in all the
files in all directories?
how to search
passing data from one jframe to anotherpassing data
from one jframe to another I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data
from a Jtextfield in the first Jframe to
another JLabel in the other JFrame.Can you please help me,
how to bring checked data from one page to anotherto bring checked data
from one page to another thanks for your help... there is
one jsp page , on it there is a link, on click of which it is opening second... fetching data
from the database on second jsp page with checkbox corresponding each
problem in sending data from one ip to another ip in JAVAproblem in sending data
from one ip to
another ip in JAVA Hi guys .
this is naveen kumar...i need a help.
i want to connect
one ip to
another ip... device in JAVA.
i know
how to ping but don't
how to send the msg's to
another IP
calling one jap page from another jsp pagecalling
one jap page
from another jsp page i created a button in
one jsp page i need to call
another jsp page as an action to that button. so
how can i call.. plz any
one explain. its urgent
How to copy a file in javaHow 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