11:41 am - Wednesday May 24, 2017

Returns the number of unallocated bytes in the partition named by this abstract path name using long getFreeSpace()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

        These methods are useful when we want to write some data on disk and need to know howgetFreeSpace provides the available free space

EXAMPLE PROGRAM


import java.io.File;

public class LongFreeSpace {

   public static void main(String[] args){

     File file= new File("c:");
             //gets the free space in C drive in Byte
       long freeSpace=file.getFreeSpace();
      System.out.println("Free Space in Byte:"+freeSpace);
           
       //gets the usable space in c drive in Byte
       long usableSpace=file.getUsableSpace();
	         System.out.println("Usable Space in Byte:"+usableSpace);
   }
}


 

OutPut:

Free Space in Byte:81384144896

Usable Space in Byte:81384144896

Explanation:

These methods are useful when we want to write some data on disk and need to know howgetFreeSpace provides the available free space. getUsableSpace provides the space available to virtual machine. These methods returns long value and these are Byte data.

much space are there to write data successfully. This is possible that just after getting disk space information from File class method, any other resource has written some data on disk. So these File class method are not giving guarantee to write data successfully.

Parameters:Na

 Returnvalue:

This method returns unallocated bytes on the partition.

Exception:

  • SecurityException — if a security manager exists and it denies RuntimePermission(“getFileSystemAttributes”) or its SecurityManager.checkRead(String) denies read access to the file name by this abstract pathname.

 

BACK

Filed in: Z-A All Java Codes

Comments are closed.