You are here:

Java/Automatically copy a file in Java

Advertisement


Question
Is it possible to find a file in Java and then automatically make a copy (duplicate) of that file. For example, one class is created to find the desired file and then another class is created to automatically make a copy of that file.

Answer
If you know the name of the file and the directory it is in, you can use listFiles() to get a list of all files, and isDirectory() to determine if it is a directory you want to traverse.

If it put a file somewhere on the file system, you might have some issues.

If you want to copy a file see the Files class.

Java

All Answers


Answers by Expert:


Ask Experts

Volunteer


Artemus Harper

Expertise

I have a Masters in computer science. I can answer questions on core J2SE, swing and graphics. Please no questions about JSP or J2ME.

Experience

I have experience in Core Java, good background in Java swing/gui, some experience with JNI, Java reflection. Some experience in bio-informatics. Basics in c++ and c#

Organizations
Washington State University

Education/Credentials
MS in Computer Science from Washington State University and a BS in Mathematics and Computer Science from Central Washington University.

©2016 About.com. All rights reserved.