Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Copying Files

Posted on 2002-03-14
3
178 Views
Last Modified: 2010-03-31
People,

Which class, or set of classes facilitate the copying of files ?  Please note that I dont really want to open a file, read it in and write its contents to another file, i want to actually do a proper copy.  

There must be a class that will allow

myObj.copyFile("from", "to");
// or maybe from and to would be File objects.

Please tell me that there is a class that will do this.  A code snippet would be helpful too .

Cheers

Mehdi
0
Comment
Question by:mehdi
3 Comments
 

Expert Comment

by:108093233315
ID: 6864683
In Java there is no way to copy a file without opening it. Other solutions are platform dependend and not possible in Java.
Here is a simple Example of the copyFile() method:

public void copyFile(String src, String dest) throws IOException
{
  InputStream is = new FileInputStream(src);
  OutputStream os = new FileOutputStream(dest);
  byte[] buffer = new byte[0xffff]; // buffer size = FFFF hex
  int nbytes;

  while ((nbytes = is.read(buffer)) != -1)
  {
    os.write(buffer, 0, nbytes);
  } // while ((nbytes = is.read(buffer)) != -1)

  is.close();
  os.close();
} // public void copyFile(String)
0
 
LVL 1

Author Comment

by:mehdi
ID: 6864699
This question has already been answered.. i posted the question twice by accident.. darn refresh :)

Sorry.. I will now write and ask them to remove this repeat question.

Mehdi
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6879768
Thank you, 50 points have been refunded to you for this duplicate question.

As you are aware, this can be avoided by not hitting submit more than once, not using your Browser's back, refresh/F5 functions, but rather our application interface's Reload button when needed.

Item closed and moved to the PAQ at zero points rather than deleting at this time so you are advised of this refund.

Moondancer - EE Moderator
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse shortcuts 9 62
HTTPSessionBindingListernter not configured in deployment descriptor 2 65
map related example 6 55
restrict decimal places for double datatype 10 19
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
The viewer will learn how to implement Singleton Design Pattern in Java.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question