Solved

java  file copy and rename

Posted on 2014-12-24
2
337 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now