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:

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Java Get Free Space
Post your Comment