I'm trying to declare a long value in Java, which unfortunately does not work.
This is my code. It results in the following error message: "The literal 4294967296 of type int is out of range".
long bytes = 4294967296;
I need this value to make a file filter that filters out files that are bigger than 4294967296 bytes (4GB). The other way round works without any issues (long size = file.length()
) with every file size, which is why I can't figure out why my declaration is not working.
Add L
to the end of the number:
long bytes = 4294967296L;
To answer your question title, the maximum value of a long can be obtained via the constant:
Long.MAX_VALUE
To solve your problem - add the l
(L
) literal after the number.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With