public static long size(Path path)throws IOException
Returns the size of a file (in bytes). The size may differ from the actual size on the file system due to compression, support for sparse files, or other reasons. The size of files that are not regular files is implementation specific and therefore unspecified.
Parameters:
path – the path to the file
Returns:
the file size, in bytes
Throws:
IOException – if an I/O error occurs
SecurityException – In the case of the default provider, and a security manager is installed, its checkRead method denies read access to the file.
package com.candidjava.filenio; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class FileSize { public static void main(String[] args) { try { Path path = Paths.get("F:/Filesnio/readline.txt"); long result; result = Files.size(path); System.out.println("File Size in bytes:" + result); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } } }