The following program displays the Free Space in various sizes of measurement Byte,KB,MB and GB for a particular drive.
package file_pkg;
import java.io.*;
public class file_cnt_words {
public static void main(String args[]) throws IOException
{
File file;
file=new File("D:/2011/Java Examples/files/file_txt.txt");
//D:/2011/Java Examples - getPath(); - get the path shows "PACKAGE FOLDER"
//file=new File("files/file_txt.txt");
sop(file.getAbsolutePath()); // Complete path
// Find Space on HDD
sop("Free Space in Drive is : "+file.getFreeSpace()+"Bytes");
sop("Free Space in Drive is : "+file.getFreeSpace()/1024+" KB");
sop("Free Space in Drive is : "+file.getFreeSpace()/1024/1024+" MB");
sop("Free Space in Drive is : "+file.getFreeSpace()/1024/1024/1024+" GB");
}
static public void sop(Object input)
{
System.out.println(input);
}
}
No comments:
Post a Comment
Please add value. Sharing is caring