copy file

copy file

View Answers

September 21, 2009 at 4:13 PM

Hi Friend,

Try the following code:

import java.io.*;

public class CopyFile{
public void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
OutputStream out = new FileOutputStream(dst);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
}
public static void main(String[] args) throws Exception{
CopyFile file=new CopyFile();
file.copy(new File("C:\\Answers\\Master.txt"),new File("c:\\java\\Master.txt"));
System.out.println("File is copied successfully");
}
}

Thanks









Related Tutorials/Questions & Answers:
copy file - Java Beginners
copy file  i want to copy file from one folder to another  ... CopyFile{ public void copy(File src, File dst) throws IOException...(String[] args) throws Exception{ CopyFile file=new CopyFile(); file.copy(new
Copy .mdb file for backup.
Copy .mdb file for backup.  hi.. i am new to java... in my application , at one place for taking back up i have to copy .mdb file from one place... tell me for multiple files of multiple type...how we can copy.. thank you
Advertisements
Java Copy file example
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
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
How to copy a file in java
How to copy a file in java In this section you will learn about how to copy... direct way to copyfile.  What we can do is, read a content of one...; FileUtils.copyFile(source file , destinationfile), which allows you to copy a file
How to copy a file
How to copy a file In this section, you will learn how to copy a file using...;} } The above code makes a copy of the file... creates two File instances to specify source and destination file respectively
Copy Directory or File in Java
srcPath, File dstPath): The copyDirectory() method is used to copy contents... Copy Directory in Java      ... how to copy the directory and files into a new directory. In this program, you
copy file from folder to folder - Java Beginners
copy file from folder to folder   my requirement is I need to copy... wich contains the file to be copied. I want to copy the file from..... it varies can you please provide sample example to copy the file regards
apache commons io copy file example
apache commons io copy file example  Hi, I want to copy one file... apache commons io copy file example. Thanks   HI, Here is the maven...; <version>2.6</version> </dependency> Now you can copy file
File copy through intranet - Java Beginners
File copy through intranet  Can i copy files from system A to System B connected through intranet?? Is this possible through java IO? If yes, please let me know
PDF Copy(File) has many pages.
PDF Copy(File) has many pages.  Dear All, I make Jasper Report it compile ,run and view properly. when i am try to send it pdf format it also sent it it pdf properly. but a that PDF Copy(File) has many pages. single copy
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find... in Java which will help in writing code for copy the file in just few lines of code... directory? My program should be able to copy the file of any size. Our program does
FTP file copy problem? - Java Beginners
FTP file copy problem?  Hi, Can any one tell me how to set file...-net-1.4.1.jar to copy files from local system to server. Eg: local file name ?test.doc? (Today, December 29, 2009, 5:09:33 PM) when I moving this file to server, the files
Copy file in php, How to copy file in php, PHP copy file
Learn How to copy file in php. The PHP copy file example explained here.... The copy function in PHP is used to copy the content of one file into another file.ADS_TO_REPLACE_1 Syntax of Copy file in PHP boolean copy ( string $source_file
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 a java with example code Thanks   Hi, Please check the thread File
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 a file to other destination and show the modification time of destination file
Copy a file to other destination and show the modification time... checks all the condition before copy to destination file, for example- source... have checked all the things so we can copy the file now
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 file?  Hi, i'm trying to code that copy the content of all txt file in a folder and paste it into one file. My following code is working
Copy text file in a HTML form.
Copy Text File in a HTML form For copying a text file from one source to other... action into php code to copy the file. In PHP code, first begin the PHP tag,ADS_TO_REPLACE_1 Define the source file and destination file variable. Copy file
Array copy
Array copy  Hello all. could someone telle me how to copy an array (holding random numbers) to a new array...( then make randomnumbers on this new array ) but without changing the excisting array ? last . possibility
copy() example
Copying a file in PHP In this example, you will learn 'how to copy a file in PHP programming language?' For copying a file, we use copy command from source...\\upload\\myfile.txt"; if(copy($source, $destination)) { echo "File
Copy Files - Java Beginners
Copy Files  I saw the post on copying multiple files (http... into a .txt file, importing that, and then somehow having Java read the filenames and then copy it to the folder I need. Does anyone have a similar program
Posting Copy and Paste HTML
Posting Copy and Paste HTML   Posting Copy and Paste HTML
cut,copy,paste
cut,copy,paste  plz... give me the coding of cut,copy and paste in Java (Netbeans
Java - Copying one file to another
;}   } } Download File Copy Example... Java - Copying one file to another       This example illustrates how to copy contents from one
data copy - SQL
data copy   how to copy values of one column from one table into another column of another table?  Hi INSERT INTO table_name (column_name) AS SELECT DISTINCT VALUES FROM table_name (column_name
Copy and pasting - Java Beginners
Copy and pasting  hi all, I am copying some cells from excell... JPopupMenu popup; JTable table; public BasicAction cut, copy, paste, selectAll...); copy = new CopyAction("Copy", null); paste = new PasteAction("Paste",null)  
JavaScript Copy Array
JavaScript Copy Array     ... useful in complex applications. In this section, you will study how to copy an array...; <h2>Copy Array Example</h2> <script language="javascript
file
file  how can copy the information in the file to the string?   Store file data into String
File
File  How to create .Exe file in jana
file
file  Could anyone please help me to write a code that does the following: Opens a file named MyName.txt, reads the first line from the file and displays it, and then closes the file. Thank you so much
file
file  how can add the information to the graphic file
file
file  Hi,what can delet some of the information of the file
file
file  Hi,how can delet some of the information of the file
File
File   How to find all files in our local computer using java
FILE
FILE  There is a file named Name.txt that contains information related to appliances.I want to read the contents of this file and I used the code... args[]) { try { File file=new File("Name.txt"); FileReader f=new FileReader(file
file
file  hi i want read special line of file. what am i doing ? I write... read data from file. please help me! void maketree(BtNode root,int i) throws... at the following link: Read specific line from file
Copy Mails to Xl sheet - JavaMail
Copy Mails to Xl sheet  Can somebody give me the Java code to copy outlook mails into an Xl sheet
ModuleNotFoundError: No module named 'copy-pase'
ModuleNotFoundError: No module named 'copy-pase'  Hi, My Python... 'copy-pase' How to remove the ModuleNotFoundError: No module named 'copy... have to install padas library. You can install copy-pase python with following
ModuleNotFoundError: No module named 'temp-copy'
ModuleNotFoundError: No module named 'temp-copy'  Hi, My Python... 'temp-copy' How to remove the ModuleNotFoundError: No module named 'temp-copy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'wet_copy'
ModuleNotFoundError: No module named 'wet_copy'  Hi, My Python..._copy' How to remove the ModuleNotFoundError: No module named 'wet_copy... to install padas library. You can install wet_copy python with following
ModuleNotFoundError: No module named 'copy-pase'
ModuleNotFoundError: No module named 'copy-pase'  Hi, My Python... 'copy-pase' How to remove the ModuleNotFoundError: No module named 'copy... have to install padas library. You can install copy-pase python with following
ModuleNotFoundError: No module named 'krunk-copy'
ModuleNotFoundError: No module named 'krunk-copy'  Hi, My Python... 'krunk-copy' How to remove the ModuleNotFoundError: No module named 'krunk-copy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'micropython-copy'
ModuleNotFoundError: No module named 'micropython-copy'  Hi, My... named 'micropython-copy' How to remove the ModuleNotFoundError: No module named 'micropython-copy' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'pycopy-copy'
ModuleNotFoundError: No module named 'pycopy-copy'  Hi, My Python... 'pycopy-copy' How to remove the ModuleNotFoundError: No module named 'pycopy-copy' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'sh-copy'
ModuleNotFoundError: No module named 'sh-copy'  Hi, My Python...-copy' How to remove the ModuleNotFoundError: No module named 'sh-copy... to install padas library. You can install sh-copy python with following command
ModuleNotFoundError: No module named 'sh-copy'
ModuleNotFoundError: No module named 'sh-copy'  Hi, My Python...-copy' How to remove the ModuleNotFoundError: No module named 'sh-copy... to install padas library. You can install sh-copy python with following command
ModuleNotFoundError: No module named 'temp-copy'
ModuleNotFoundError: No module named 'temp-copy'  Hi, My Python... 'temp-copy' How to remove the ModuleNotFoundError: No module named 'temp-copy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'temp-copy'
ModuleNotFoundError: No module named 'temp-copy'  Hi, My Python... 'temp-copy' How to remove the ModuleNotFoundError: No module named 'temp-copy' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'temp-copy'
ModuleNotFoundError: No module named 'temp-copy'  Hi, My Python... 'temp-copy' How to remove the ModuleNotFoundError: No module named 'temp-copy' error? Thanks   Hi, In your python environment you

Ads