Java source code examples

Java source code samples. Java code examples.

Finds out total space available in a partition using java

* * * * * 1 votes

Finds out total space available in a partition using java

The getTotalSpace method of File class can be used for getting the total space available in a partition or drive using java.

import java.io.File;
/**
 * File class examples.
 *
 */
public class FileExample  {
	public static void main(String[] args){
		// Create file object representing the source file/directory
		File file = new File("d:\\temp\\test.txt");

		// Get the total space available in current drive
		long value = file.getTotalSpace();

		// Convert it to GigaBytes
		double valueGB = (double) value / 1024 / 1024 / 1024;

		System.out.println("Total space available in the current partition is "+valueGB);
	}
}

Tags: java.io

Discuss This Code