1. Introduction
The length() method from Java IO returns the length of the file. If given File object represents the directory the method will return unspecified value.
2. Method signature
Parameters:
- method does not take any parameter
Returns
- long - the file lenght in bytes, or 0L if the file does not exist
Throws
- SecurityException - when we do not have access to the file or directory
3. Examples
3.1. Print length of the file that does not exist and file with a short text inside
The output:
4. Conclusion
In this article, we presented a method that returns the length of the file in bytes.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}