Comment

Laurent
File copy ,
March 2, 2010 at 7:48 PM

This is another way to do the same thing from java.io.File parameters. Here, i'm throwing the IOException and leaving the caller to handle it. Also, what is the point of calling System.exit() in the 'catch (FileNotFoundException )' block?




private static void copyfile(File srcFile, File dstFile) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new FileInputStream(srcFile);
out = new FileOutputStream(dstFile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0){
out.write(buf, 0, len);
}
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
}
}
}
}
View All Comments | View Tutorial
Advertisement
Related Tutorial and Articles
Java Beginners

copy file - Java Beginners
CopyFile{ public void copy(File src, File dst) throws IOException...copy file  i want to copy file from one folder to another  ...(String[] args) throws Exception{ CopyFile file=new CopyFile(); file.copy(new 

Java Technology Tutorials

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 

Core Java

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.... In another way we can copy using File I/o Stream. Example:  Java Code to copy 

Java Beginners

Copy Files - Java Beginners
into a .txt file, importing that, and then somehow having Java read the filenames...Copy Files  I saw the post on copying multiple files (http://www.roseindia.net/java/example/java/io/CopyMultipleFiles.shtml) and I have something 

Java Beginners

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 

Java Beginners

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 

Java Technology Tutorials

How to copy a file
How to copy a file In this section, you will learn how to copy a file using Java IO library. For this, we have declared a function called copyfile() which...;} } The above code makes a copy of the file 

Java Beginners

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 

Java Beginners

How to copy files from one folder to another based on lastmodified date - Java Beginners
file has not mentioned."); System.exit(0); case 2: copyfile...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 

Java Beginners

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 

Java Beginners

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 

Java Beginners

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)   

General

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...; This is detailed java code that copies a source file to destination file, this code checks all the condition before copy to destination file, for example- source 

Java-Tutorials

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... you a clear idea : Example : import java.io.*; public class CopyFile 

Java-Tutorials

Copy Directory or File in Java
Copy Directory in Java      ...;        Introduction Java has... how to copy the directory and files into a new directory. In this program, you 

Java Beginners

File copy from one directory to another in java
in Java which will help in writing code for copy the file in just few lines of code...File copy from one directory to another in java  I am trying to find... directory in Java. I have to write a program in my application for copying one file 

Java Beginners

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 

Java Beginners

Copy a Html chart into PPT - Java Beginners
Copy a Html chart into PPT  Hi Experts, i am facing with a problem without solution. I have a Html site and would like to write a code so that by clicking on a button the graph will be copied in an active ppt. Could you 

Java Beginners

java - Java Beginners
java  how to write a programme in java to copy one line file to another file.name of file are entered through a keyboard  Hi Friend, Try...(); System.out.println("Destination File"); String f2=input.next(); copyfile(f1,f2 

General

Copy multiple files
copyfile() copies the contents of all given files to a specific file. When all... Copy multiple files       ... is copied to another file. The java.io package provides this facility 

Java Tips and Examples

Java - Copying one file to another
Java - Copying one file to another   ... to another file. We will be declaring a function called copyfile which copies the contents from one specified file to another specified file. copyfile(String 

Java Beginners

Java - Java Beginners
Java  Write a program to copy the contents of one file to another file removing comments and extra blanks. please reply.  Hi Friend... static void copyfile(){ try{ File f1 = new File("data.txt 

Java Beginners

Convert Class File to .java File - Java Beginners
Convert Class File to .java File  Sir, How To Convert .class file to .java File. Please Help me  Use cavaj software ,which is freeware, to convert .class to .java  Use jd-gui to convert ur .class to .java 

Java Beginners

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 the directory in to ftp server using java ?   Hello venaktehs As much... working directory with the same name (which you wish to copy) as: issueCommand 

Java Beginners

File Handling - Java Beginners
File Handling  Q. Write a java prg which accepts a list of existing...; fout3.write(ch);//copy contents of f1 to f3 if((ch>='A')&&(ch<='Z...);//copy contents of f2 to f3 } fin2.close(); fout3.close(); try 

Java Beginners

cut,copy,paste
cut,copy,paste  plz... give me the coding of cut,copy and paste in Java (Netbeans 

Java Beginners

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 

Java Beginners

FileOutputStream.write - Java Beginners
to copy a file from a source folder to a destination folder. The problem... static void copyFile(File source, File dest) throws IOException... void copyFile(String fromSourceFile, String toDirName) throws IOException 

PHP Tutorial

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 

XML Questions

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 

PHP Tutorial

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." 

JavaMail Questions

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 

Java Beginners

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 

Java Beginners

file in java - Java Beginners
file in java  I want to count the number of white line and comment line in a file (.sql) with java if you have an example thank you in advance 

Java Beginners

Program - Java Beginners
Program Java link list  I need program in Java to copy a file to another file  Hi Friend,For more informationhttp://www.roseindia.net/java/beginners/linked-list-demo.shtml 

Java Beginners

Java File - Java Beginners
Java File  Hi Friend, Thank you for the support I got previously... Anyone please send me the Java Code for scanning a directory and print.... Output Print the file names and size of the file to the console. Please 

Java Beginners

java - Java Beginners
the file into the directory using java io classes? ie i have a file like test.java and i have a directory c://java/src/... so i need to store the test.java file in the directory like c://java/src/... I need the code.....very urgent 

Java Beginners

Download a file - Java Beginners
Download a file   Hi, I need a java code to download a file from a website and before downloading it should give me an option to browse and select the location to put the file. Thanks in advance 

Java Beginners

Executale File - Java Beginners
Executale File  Plz tell me how to convert java file into .exe file... the instruction.. Good Luck i don;t know how to create the exe file for java  ... for java but you can create an executable jar file .create a MF file 

Java Beginners

jar file - Java Beginners
an application packaged as a JAR file (requires the Main-class manifest header)java -jar...jar file  jar file When creating a jar file it requires a manifest file. what is the manifest file, and how to create it. And tell me more about 

Java Beginners

IO File - Java Beginners
IO File  Write a java program which will read an input file & will produce an output file which will extract errors & warnings. It shall exclude... from the log file. This is the task assigned to me..Please help me 

Java-Tutorials

Java - Copying one file to another
:\nisha>java CopyFile a.java Filterfile.txt File copied... Java - Copying one file to another   ... how to copy contents from one file to another file. This topic is related 

Java Beginners

file handling - Java Beginners
manner. now write a progam in java and create another file which is having the amount required to purchase each item and at last read the newly created file...file handling  assume two files are there- 1. with the quanity of he 

Java Beginners

File - Java Beginners
. Here it is: Write a program to create a file named "numbers.dat". Then create... by a comma. After the file has been created, close and reopen the file and display... number integers from 1 to 100, separated by a comma to the end of the file. Reopen 

Java Beginners

file uploading - Java Beginners
file uploading   hi, i am developing one stand alone j2se programming in that i have to upload a file to another system in the LAN and have... is it should dispaly files from current system and asks whether this file is already 

Java Beginners

File Handling - Java Beginners
File Handling  Thanks for replying me.. but i am sorry to say...; System.out.print("Enter the file name : "); name = br.readLine(); name = "d...{ File f; f= new File(name); if(f.exists()){ RandomAccessFile rand 

Java Beginners

File Handling - Java Beginners
File Handling  I have written one program by which we can create a file , store any information in that,and resume that file using a user name and password.now my problem is that whenever i write datas into the file the previous 

Java Beginners

doc file - Java Beginners
doc file   i want to read .doc file ?....it is a part of my project plz help. if possible , can anyone give me the code 

Java Beginners

File Writing - Java Beginners
File Writing  Hi... I need a syntax or logic or program by which we can write into the desired shell of the Excel file from console window...  Hi friend, I am sending you a link. This is will help you. Please 

Java Beginners

Jar file - Java Beginners
Jar file  Hello this is my second question and i hope atleast i will get answer i bulid a jar file of my project using netbeans but now problem is when i open that jar file in command prompt i got error exception in thread 

Java Beginners

Setup file - Java Beginners
Setup file  Hello sir ,how i can make Java Programs Set up File.... Point to note here is that the Java compiler very well knows about...: http://www.roseindia.net/java/exceptions/how-to-throw-exceptions.shtml 

Java Beginners

Java Jar File - Java Beginners
Java Jar File  What is a Java JAR file ..and how can i open a .jar file in Java?  Just create a Jar file and Double click on it, it will automatically runs main method in that Jar : to create Project as JAR 

Java Beginners

Java source file - Java Beginners
, You can use Java Decompiler tools like "Cavaj" to decompile the .class file...Java source file  i create a file.java just now but mistakenly i delete the source file. Now i have only the class file. Is there any chance for me 

Java Beginners

file arraival in java - Java Beginners
file arraival in java  A simple java program that runs continuously as a background process and prints out according to a given event based schedule(Arrival of a file in a specified directory) and is exited only through manual 

Java Beginners

java - file delete - Java Beginners
java - file delete  I will try to delete file from particular folder... is: String dirname = null; File dir = new File("c:/writinnew...){ try { File delete = new File (incurrentFile); System.out.println 

Java Beginners

java jar file - Java Beginners
java jar file  How to create jar Executable File.Give me simple steps... int buffer = 10240; protected void createJarArchive(File jarFile, File...(); System.out.println("Jar File is created successfully."); } catch (Exception ex 

Java Beginners

java - file delete - Java Beginners
java - file delete  I will try to delete file from particular folder... is: String dirname = null; File dir = new File("c:/writinnew...){ try { File delete = new File (incurrentFile); System.out.println 

JDBC

Copy Table in a MySQL Database
Copy Table in a MySQL Database       In this section, you will learn to copy one table to another... one table to another in a same MySQL database. To copy any table,  firstly 

Java Beginners

creating an .exe file - Java Beginners
creating an .exe file  how to create an .exe file in java? thanks in advance 

Java Beginners

java - Java Beginners
java  how i can write code for task sheduling in core java ( that means we can store tasks in a file that tasks exicute with the given time)ex (: task date time : copy file1 to file 2 30/12/2009 10:35 am) that copy file work 

Java Beginners

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 

Framework Questions

How to copy text from a gif image
How to copy text from a gif image  I have some gif images that containing some important text. i want to have that text in my notepad file. i have.... so, please tell me how can i copy that text to my notepad. i am using ubuntu 

Java Beginners

java - Java Beginners
java  dear sir, plz give me a java code where we copy a files from a folder and paste in a single file by zip, and again open the all files in a single file 

Java Beginners

file i/o - Java Beginners
file i/o  hiii, i have to read some integers from a text file and store them in link list.. so please can i have source code for it.?? thanks 

Java Beginners

save text file - Java Beginners
save text file  hi i have just start programming in java.please guide me if i want to read a text file in java.then the text file is save in which directory 

Java Beginners

Creating JAR File - Java Beginners
me, in letting me know, as to how to create JAR file from my JAVA source or class files. And what is this manifest file, and what changes needs to be done... buffer = 10240; protected void createJarArchive(File jarFile, File[] listFiles 

Java Beginners

Java swing - Java Beginners
Java swing  Hi, I want to copy the file from one directory... in the source directory ,i want to copy the first file from source to destination... will be displayed. Like the first file nameis abc.txt,then the message 

Java Beginners

ftp - Java Beginners
ftp  pls tell me how to connect to a ftp server and copy a file to local machine using java, with UNIX code for copying purpose 

Java Beginners

File I/O - Java Beginners
File I/O  How to search for a specific word in a text file in java?  Hi Arnab, Please check the following code...[]){ String searchString = args[1].toLowerCase(); try { File fileName = new File 

Java Beginners

Adding a text file - Java Beginners
Adding a text file  Hello, I need a program that will search a text file of strings representing numbers of type int and will write the largest and the smallest numbers to the screen. The file contains nothing but strings 

Java Beginners

file upload download - Java Beginners
file upload download  how to upload and download files from one system to another using java.io.* and java.net.* only please send me code 

Java Beginners

File I/O - Java Beginners
File I/O  Suppose a text file has 10 lines.How do I retrieve the first word of each line in java? abc fd ds 10 fg yy6 uf ui . . . . . . yt... and send a text file as argument. ============================== import 

Java Beginners

upload and download a file - Java Beginners
upload and download a file  how to upload a file into project folder... the following code: 1)page.jsp: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload 

Java Beginners

file upload in jsp - Java Beginners
file upload in jsp  how to upload a file using jsp. my operating...: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload:   2 

Java Beginners

java use dll file - Java Beginners
java use dll file  how to execute dll file in java 

Java Beginners

Create JAR file - Java Beginners
. But do let me know, isn't there any other way of making a JAR File. Simply like... each time in order to run your JAVA program on some other computer, it;s better to make a JAR file and run it easily on any computer. For that purpose i want 

Java Beginners

To find palindrome no in a file - Java Beginners
To find palindrome no in a file  hi all i am having a problem...I wanted to write one java program where i have to count the no of palindrome in a file. I tried it with my own but not able to get result.pls help me out   

Java Beginners

file upload in jsp - Java Beginners
file upload in jsp  how to upload a file in jsp and store it in my... += byteRead; } String file = new String(dataBytes); String saveFile...)).getBytes()).length; File f = new File("C:\\"+saveFile); FileOutputStream fileOut 

Java Beginners

list file number - Java Beginners
list file number  sir you still haven't understand my problem. i...[] args) throws IOException{ int countF=0,countD=0; File f = new File( "C:\\" ); File[] listOfFiles = f.listFiles(); for (int i = 0; i < 

Java Beginners

Creating JAR File - Java Beginners
, which says, Failed to load Main-Class manifest attribute from H:\Stuff\NIIT\Java... to change the contents of my manifest file. I read somewhere regarding i have to add a line to my manifest file (i.e. Main-Class: mypackage.MyClass 

Java Beginners

pass parameter - file - Java Beginners
pass parameter - file  Hi, I want to pass paramter file to method... immediately. file.jsp ========== File Parameter Use Please Select the file 2. Display.java 

Java Beginners

Writing xml file - Java Beginners
XmlServlet().createXmlTree(doc); System.out.println("Xml File Created... = sw.toString(); File file = new File("c:/newxml.xml... FileOutputStream(file))); bw.write(xmlString); bw.flush 

Java Beginners

set java exe file as background - Java Beginners
set java exe file as background  hi frenz, i am begineer to java. in my application i have a one exe file. now i wanna the file... is closed then v don't continue that application.. can u tell me how java exe file set 

Java Beginners

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 

Java Beginners

file
file  how can copy the information in the file to the string?   Store file data into String 

C Tutorials

C String Copy
by the header file <string.h> that will copy the specified string from st1... C String Copy       In this section, you will learn how to copy the string in C. You can see 

Java Beginners

java-jar file creation - Java Beginners
java-jar file creation  how to create a jar file?i have a folder... file  Hi Friend, JAR stands for the Java Archive. This file format is used to distribute a set of java classes. This file helps you to reduce the file 

PHP Tutorial

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 

Java Beginners

edit msword file - using java - Java Beginners
edit msword file - using java  I want to edit ms word file. That is input file font style is times new romen and font size is 12. I want the output file font style is bookman old style and size is 20. How to possible java 

Java Beginners

Java swing - Java Beginners
Java swing  Hi, I want to copy the file from one directory... in the source directory ,i want to copy the first file from source to destination... javax.swing.text.html.*; public class Copy { final static int interval 

Java Beginners

read excel file from Java - Java Beginners
read excel file from Java  How we read excel file data with the help of java?  Hi friend, For read more information on Java POI visit to : http://www.roseindia.net/java/poi/ Thanks 

Java Beginners

J2ME delete file - Java Beginners
 

Java Beginners

java code to upload and download a file - Java Beginners
java code to upload and download a file  Is their any java code to upload a file and download a file from databse, My requirement is how can i..., one user send one a.doc file to x ,he has to download his a.doc another 

JDBC

Copy One Database Table to Another
;java CopyOneDatabaseTableToAnother Copy data from one database table... Copy One Database Table to Another       In this section, you will learn to copy one database table 

Java Beginners

Java Binary data file - Java Beginners
Java Binary data file  Hi, I have a binary data file(binfile.data) and the file has what is commonly referred to as variable length records.Specifically the format of the file is: HEADER SECTION//RECORD 

Java Beginners

Non Editable Text File in java - Java Beginners
Non Editable Text File in java  Hello Sir ,I want to Show NonEditable TextFile on JButton Click which Contains User Manual of Project ,How I can Do It. plz Help Me 

Java Beginners

java program for writing xml file - Java Beginners
java program for writing xml file  Good morning i want to write values from my database(one table)into one xml file. Like i have 3 coloumns in my... xml file and storet that in particlar location. Please help me out Thanks 

Java Beginners

Java Compilation - Java Beginners
want the second file to be a copy of the first file, except that all...Java Compilation  I want to write a Java program that asks the user for the names of 3 files. I want the first file to be opened for reading 

Java Beginners

download a file from browser - Java Beginners
download a file from browser  How to download a file from browser and save it in local path 

Java Beginners

Java progrm
;Java Copy File import java.io.*; import java.util.*; public class CopyFile{ private static void copyfile(String srFile, String dtFile){ try{ File f1...Java progrm   Write a Java progrm that copies one text file 

Advertisements Advertisements
 

 

 

DMCA.com