Home Discussion Discuss: Java - Copying one file to another

  • Way to indent, guys.It's not really that hard August 12, 2011 at 12:20 AM

    The way your code is all indented at the same level really makes it harder to read, and it looks amateurish. You should really work on that.

  • Better still... (exception safe with multicopy)kriechend September 15, 2011 at 5:17 AM

    private static void copyFiles (final File dest, final File ... files) throws IOException { if (! dest.isDirectory ()) throw new FileNotFoundException ("Destination is not a directory: " + dest.getAbsolutePath ()); for (final File file : files) { final InputStream istream = new FileInputStream (file); try { final OutputStream ostream = new FileOutputStream (new File (dest, file.getName ())); try { final byte [] buffer = new byte [8096]; while (true) { final int count = istream.read (buffer); if (0 < count) break; ostream.write (buffer, 0, count); } } finally { ostream.close (); } } finally { istream.close (); } } }

  • ReplyRedAlert May 26, 2013 at 7:27 PM

    Thanks you so much! You help me a lots! :)

  • vCJKmAEgNMOwQppuSandy September 23, 2011 at 6:52 AM

    Information is power and now I'm a !@#$ing dcittaor.

  • cor javapratul October 11, 2011 at 1:54 PM

    i want ditals program logics o file handling like 1.copy one file in to anather 2. two files copy into one file. 4.count the word in file. 5.count the lines in file. 6.count the charater in file. 7.and new methos of file handling.

  • java quesryashish October 15, 2011 at 11:55 AM

    plz give solution of 1. Write File I/O programs for following operations : i) Copy a file ii) Replace a word with another word in a file iii) Working as linux ‘cat’ command iv) List files and directories within a file. v) Append within a file. vi) Count number of words within a file using console i/o 2. Define a layout manager in java, and explain its type and working in detail using a program. 3. Write a program to demonstrate generics in java using generic class, generic interface and its implementation class, generic constructor and generic methods. 4. Demonstrate multithreading using any sample application. 5. Implement a tcp client server program.

  • Trouble with CopyFile exampleDave Pierce November 13, 2011 at 8:07 PM

    Thank you for all the example java programs. Most have been quite helpful. I am having trouble, however, with the CopyFile example. As written, it always defaults to args.length = 0, therefore not very useful. How is this CopyFile class used in a real example with source and destination filenames listed?

  • javarajesh January 23, 2013 at 1:15 AM

    thanks alot, its working with .doc file

  • java relatedkvreddy February 9, 2012 at 9:18 PM

    hey post all commands pdf in your web site. how to do that commands

  • file and content names onlyKorn2 February 23, 2012 at 4:01 PM

    Hi Does any one know if there is a code to where you can copy a file name save it as a name only and then copy the content of the same file and save only the names of that for example .exe, jpeg, .dvx ect.. My aim is to copy only the so that a dont sit with dubble files on the pc. If there is any awnsers please email me at ndr_lttr@hotmail.com Thank you

  • JavaAnkur Yadav April 3, 2012 at 1:19 PM

    no comments

  • ThanksNot Interested October 1, 2012 at 6:23 PM

    Your Simple and to the point examples always make me to visit your website at first place whenever I needs some help related to Java.

Post your Comment



Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Related Articles
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...;This string is copied from one file to another\n"); bf.close(); InputStream 

Java Beginners

converting one file format to another
converting one file format to another  Hi ser I need a code to export data from data grid to PDF and XL format plz help me out 

Java-Tutorials

How to write content of one file to another file.
is : 1836825431 Content of one file successfully written in other file...; In this example we will open a file and then write the content in new file... of the data being written in the second file. About CheckedOutputStream class 

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... copy from one directory to another in java. Thanks 

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 

Programming Tutorials

How to write content of one file to another file and calculate checksum for accuracy.
on the output stream.  In this Example, we will write the content of a file to another file. And calculate the value of checksum at writing time with the help...CheckSum Calculation in java This example calculate the checksum 

Java Beginners

how to pass a string from one class to another
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 a string from one class to another  hi all, Good morning 

Struts Questions

How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both
How to include Two multi rows, one with a file Upload and another with normal fields, have problem while including both  How to include Two multi rows, one with a file Upload and another with normal fields, have problem while 

JSP Interview Questions

Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving it
Passing a 2 Dimentional Array From one Jsp to Another Jsp file and Retreving... are dynamically stored into it in one jsp file .I passed this array into another Jsp File and when i tried to retrieve the data in the 2 Dimensional array 

JSP Servlet Questions

calling one jsp from another jsp - JSP-Servlet
calling one jsp from another jsp  Hi All, In my web application... in two.jsp by using jsp declarative tag. Now from one.jsp file I want to call the method of two.jsp file. after executing the two.jsp's method processing should 

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... this will be helpful for you http://www.roseindia.net/java/example/java/io 

JSP Servlet Questions

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  ... a .jsp( say abc.jsp) file which contains multiple Action form.I am required to add one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise 

HTML Questions

one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame 

XML Questions

parser xml one page to another
parser xml one page to another  parser xml one page to another 

General

Convert One Unit to Another
Convert One Unit to Another       Again in this section, you will learn to convert One Unit to Another. The following program helps you in converting some more units to another.  

JSP Servlet Questions

calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent 

Java Beginners

How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm 

Java Beginners

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..., String dtFile){ try{ File f1 = new File(srFile); File f2 = new File 

Java Beginners

how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can 

Java Interview Questions

how to seperation one file into two - Java Interview Questions
how to seperation one file into two  hi can anyone tell me how to seperation one file into two so that the data inside e.g a=apple will get seperated and comes as a in one file and apple in another 

SQL Question

update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products... enter the Quantity field in table 'Products_Purchased'In table 'Products' one item 

JSP Servlet Questions

how to set the tables one is left and another one is right - JSP-Servlet
how to set the tables one is left and another one is right  Here two tables are combined.i need to set the one table is left another one is right and ineed to gap between the two tables Document document=new Document 

JSP Servlet Questions

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 other.i.e. First JSP is communicating with the second JSP, Second JSP 

JSP Servlet Questions

how to change password into one jsp to another jsp
how to change password into one jsp to another jsp  i have two jsps in one jsp i give one password and confirm password, in another jsp i want change my password compare with 1st jsp how to write code please give me answer?   

Java Beginners

passing data from one jframe to another
passing 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 

General

Many Public Classes in One File - Java Tutorials
Many Public Classes in One File 2003-10-13 The Java Specialists' Newsletter [Issue 080] - Many Public Classes in One File Author: Dr. Heinz M. Kabutz... Java classes in China. I was talking about Java only allowing one public 

Programming Tutorials

Sort file data and write into another file
Sort file data and write into another file By sorting, you can arrange the data into meaningful order and analyze it more effectively. Here we have one file... is then written into another file new.txt. Here is the student.txt file: 4 A 87 

JSP Servlet Questions

to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help but my problem is different, i am stating my problem below. in my project there is one jsp page , on it there is a link, on click of which it is opening second 

Java Server Faces Questions

How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my jsf code... <%@ page language="java" contentType="text/html; charset... submitting the form it navigate to the following page :- <%@ page language="java 

JSP Servlet Questions

passing .properties file as a parameter to another function
passing .properties file as a parameter to another function  passing .properties file as a parameter to another function in an jsp file 

DMCA.com