0

How can I 'cut' byte array using Arrays.copyOfRange with long parameters?

EDIT: I need to cut file ( not larger than 2GB ) from byte index to the end of file ( byte[].length )

int size = f.length()

throws: incompatible types: possible lossy conversion from long to int (even if the file is 600kB)

File f = new File("path-to-file");
byte[] bytes = Files.readAllBytes( f.toPath() );

long indexToCutFrom = a_long_number; 
long indexToCutTo = f.length() - 1;

// method with these parameters does not exists
byte[] cuttedBytes = Arrays.copyOfRange( bytes, indexToCutFrom, indexToCutTo );
t4dohx
  • 675
  • 4
  • 24

1 Answers1

0

Arrays are limited to a length of Integer.MAX_VALUE (= 2 ^ 32 -1). No need of long.

In short, you can't because you don't need to.

You can see it simply because Arrays.length() is an integer.

AxelH
  • 14,325
  • 2
  • 25
  • 55