Home Java Java-get-example Java Get Free Space
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java Get Free Space

Advertisement
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:

 

Download Source Code

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 24, 2008

Related Tutorials

Ask Questions?    Discuss: Java Get Free Space  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com