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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Varun
copy file
1 Answer(s)      5 years and 3 months ago
Posted in : Java Beginners



Advertisement
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 .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
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
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
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
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
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
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
Copy Directory or File in Java
Copy Directory in Java      ... how to copy the directory and files into a new directory. In this program, you will see how contains of a directory or a file is copied  from
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
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. Syntax of Copy file in PHP boolean copy ( string $source_file, string $target
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... can copy the file now.*/ fis = new FileInputStream
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, Define the source file and destination file variable. Copy file from source
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...;; if(copy($source, $destination)) { echo "File copied successfully."
Posting Copy and Paste HTML
Posting Copy and Paste HTML   Posting Copy and Paste HTML
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
cut,copy,paste
cut,copy,paste  plz... give me the coding of cut,copy and paste in Java (Netbeans
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)  
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
JavaScript Copy Array
JavaScript Copy Array     ... useful in complex applications. In this section, you will study how to copy an array... using JavaScript.. <html> <head> <h2>Copy
copy string to string objective c
copy string to string objective c  How to copy a value of NSString to another string in Objective C? I have to different views and i am will to show the NSString value in both of them. Thanks
Java - Copying one file to another
);   }   } } Download File Copy... Java - Copying one file to another       This example illustrates how to copy contents from one
how to copy the directory in to ftp server using java
how to copy the directory in to ftp server using java  how to copy... working directory with the same name (which you wish to copy) as: issueCommand... directory.For example : ftp.setLocalDir(new File("C:/tmp"); Now you can upload
file
file  how can copy the information in the file to the string?   Store file data into String
 

 

 

DMCA.com