0

I have the same name csv files appened with Timestamp at server. I want to copy one file at a time, removing the timestamp to another location. For example the files are present as under at the server: MyFile_20140226.csv MyFile_20140227.csv MyFile_20140228.csv

I need to copy one file at a time removing the timestamp from the name of file as MyFile.csv to another location.

How should I get the filename sequentially removing the timestamp in java.

user1602657
  • 141
  • 2
  • 6
  • 8

1 Answers1

0

You could just rename the file. When you rename it, you can also change the directory it's in. This would essentially move and rename the file:

if(new File("C:\\old\\path\\" + "MyFile_20140226.csv").renameTo(new File("C:\\new\\path\\" + "MyFile.csv"))
    System.out.println("File is moved successful!");
else
    System.out.println("File is failed to move!");

Source 1

Source 2

NOTE 1: There are better, cleaner, and safer ways to do this. Look at the sources. I just wanted to give some minimal example.

NOTE 2: I would highly recommend doing some research yourself (use Google). There are many examples online.

Community
  • 1
  • 1