Close

Java IO & NIO - Files.size() Examples

Code Snippets Java IO & NIO Java Java API 


Class:

java.nio.file.Files

java.lang.Objectjava.lang.Objectjava.nio.file.Filesjava.nio.file.FilesLogicBig

Method:

public static long size(Path path)
                 throws IOException

Returns the size of a file (in bytes).

Parameters:
path - the path to the file
Returns:
the file size, in bytes


Examples


package com.logicbig.example.files;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class SizeExample {

public static void main(String... args) throws IOException {
Path path = Files.createTempFile("test-file", ".txt");
Files.write(path, "some content....".getBytes());

long size = Files.size(path);
System.out.println(size);
}
}

Output

16




See Also