3

how can I copy an existing excel macro file "test.xlsm" to a new Excel file in the same directory ("test copy.xlsm")? I have used this approach:

private static void copyFileUsingJava7Files(File source, File dest)
        throws IOException {
    Files.copy(source.toPath(), dest.toPath());
}

However, I cannot specify the filename of the copied file here and get a handle to use it afterwards. How can I achieve that?

cheers

Benjamin
  • 10,603
  • 3
  • 16
  • 28

2 Answers2

2

As written in the documentation the action will fail if the destination already exists. You should only give a path instead of the file as second parameter. If you want to overwrite the destination you should add the specific option.

More information: http://docs.oracle.com/javase/7/docs/api/java/nio/file/Files.html

To get the destination file you can simply return it afterwards.

red13
  • 427
  • 4
  • 12
1

'File dest' is a file object that contains the destenation file name. you create it like:

new File("/data/home/test copy.xlsm")
Eli Skoran
  • 238
  • 1
  • 10