Solved

java  file copy and rename

Posted on 2014-12-24
2
475 Views
Last Modified: 2015-01-07
Hi

I had a file named "testnow.txt" and i want to make this file 95 copies.. in the same folder
I know how to rename the file and how to copy an existing file, how do you do both at a time.
here's what i want....
i want to duplicate the "testnow.txt" and rename it like
testnow_1.txt
testnow_2.txt
testnow_3.txt
.
.
.
.
testnow_95.txt

Thanks,
0
Comment
Question by:shragi
[X]
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
2 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 40516859
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40516898
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.Path;
public class Q_28586536 {
    public static void main(String[] args) {
          Path src = Paths.get("testnow.txt");
          for( int i=1;i<=95; ++i ){
            Path dest =  Paths.get("testnow_" + i + ".txt");
            try {
                Files.copy(src,dest);
            } catch (IOException e) {
                e.printStackTrace();
            }
          }
   }
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
maven disable workspace resolution 1 38
Why doesn't this text field show up on my Applet frame? 2 28
programming a polycom voip phone 3 54
What browser will run Java? 7 125
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

749 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