cancel
Showing results for 
Search instead for 
Did you mean: 

soap groovy copt file - inChannel.transferTo & Files.copy(

SOLVED
New Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Moderator

Re: soap groovy copt file - inChannel.transferTo & Files.copy(

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.  

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

2 REPLIES 2
Highlighted
Moderator

Re: soap groovy copt file - inChannel.transferTo & Files.copy(

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.  

 

Natalie
Customer Care Team

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓

View solution in original post

Highlighted
Community Manager

Re: soap groovy copt file - inChannel.transferTo & Files.copy(

@JesperJ , were you able to solve this?

 

Thank you NBorovykh!



Sonya Mihaljova
Community and Education Specialist

 Join SmartBear Connect next April in Boston to meet with software development, API and testing experts from around the world! Get your ticket today!