Groovy: get byte array from file returns different values each run
I want to get an byte array of a file via groovy. I use this:
def contents = new File(filePathName).bytes
"filePathName" is defined as d:\test.txt
test.txt contains "Hello!"
If I execute the script in SoapUI it returns
The next time, same file, same everything, just a new execution, it returns for example:
and so on.
Why is that?
I get a similar response when I use a larger zip file for this.
The path is correct, If I change it to something wrong, or change the file name to something invalid, I get an error message.
Solved! Go to Solution.
I think what you're seeing is the object id, which changes every time you call the script.
As bytes is an array, you need to access it like an array, E.g.
byte bytes = new File(filePathName).bytes; log.info(bytes); log.info(bytes);
Or, the whole array....
byte bytes = new File(filePathName).bytes; log.info(bytes.toString());
Note how the values are the same each time you call it.