soap groovy copt file - inChannel.transferTo & Files.copy(
I'm loosing my mind over this, every time I find some examples online that should work they either throw loads of messages or it just does not work. SOap 3.0 pro on Windows 10.
I need to make a copy of an xlsx file to a path of my choosing.
I click run, but nothing happens. No error msg, no log info. I'm fed up with groovy.
private static void fileCopyUsingNIOChannelClass() throws IOException
{
File fileToCopy = new File("c:/temp/template.xlsx");
FileInputStream inputStream = new FileInputStream(fileToCopy);
FileChannel inChannel = inputStream.getChannel();
File newFile = new File("c:/temp/template1.xlsx");
FileOutputStream outputStream = new FileOutputStream(newFile);
FileChannel outChannel = outputStream.getChannel();
inChannel.transferTo(0, fileToCopy.length(), outChannel);
inputStream.close();
outputStream.close();
}
Also I tried this, smae **bleep**:
Path source = Path.get("C:/temp/ISPC-OUTPUT.xlsx")
Path destination = Path.get("C:/temp/ISPC-OUTPUT1.xlsx")
Files.copy(source, destination);
It's as if the program never compiles the code, but I get a blue star.
Hi JesperJ,
The below code works for me. Please copy the full snippet to your Groovy Script test step, correct the file paths and try it out.
import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.Files; Path source = Paths.get("C:\\Temp\\source.xlsx") Path destination = Paths.get("C:\\Temp\\destination.xlsx") Files.copy(source, destination);
You can enhance it as it's described here to handle the situation when the destination file already exists in the location.