In this section, you will study how to obtain available free space in the specified file. In the given example, we have provided the path of file 'Hello.txt' to the constructor of class File.
Java Get Free Space
In this section, you will study how to obtain available free space in the specified file. In the given example, we have provided the path of file 'Hello.txt' to the constructor of class File.
file.getFreeSpace()- returns the number of unallocated bytes of the file.
Here is the code of GetFreeSpace.java
import java.io.File; public class GetFreeSpace { public static void main(String[] args){ File file = new File("C:\\Hello.txt"); long value = file.getFreeSpace(); System.out.println("Total free space available in the file is "+value+" B"); } } |
Output will be displayed as: