Forum Discussion

Terkon's avatar
Terkon
Contributor
4 years ago
Solved

Groovy: get byte array from file returns different values each run

Hi!   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 ex...
  • ChrisA's avatar
    4 years ago

    Hi,

     

    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[0]);
    log.info(bytes[1]);

     

    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.