Solved

java  file copy and rename

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
print map entry 34 68
servlet  URL Rewriting 1 36
factorial example 4 39
Can anyone please tell me why i can not find ID  investorCoolGrid inside the jsp page? 1 20
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 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