Home Tutorial Java Core Files Java file get total space

 
 

Share on Google+Share on Google+
Java file get total space
Posted on: April 25, 2006 at 12:00 AM
Advertisement
In this section, you will learn how to get the total space of disc.

Java file get total space

In this section, you will learn how to get the total space of disc.

Description of code:

JDK 1.6 provides few new methods ? getTotalSpace(), getUsableSpace() and getFreeSpace(), bundled with java.io.File. These methods provides essential information regarding disk space.

In the given example, we have created an instance of a File to represent a disc of our file system. Then we have called the method getTotalSpace() of class File through the object of File class.

getTotalSpace() method- This method returns the actual size of the disc.

Here is the code:

import java.io.File;

public class FileTotalSpace {
	public static void main(String[] args) {
		File file = new File("C:");
		long totalSpace = file.getTotalSpace();
		System.out.println("Total Space = " + totalSpace + " bytes");
	}
}

You can find the total space of a disc or partition using the method getTotalSpace().

Output:

Total Space = 36388605952 bytes
Advertisement

Related Tags for Java file get total space:


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: April 25, 2006

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com