12:16 pm - Sunday June 25, 2017

Java Program get totalspace program to get size of a partition where abstract file exists using getTotalSpace() method

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

Get totalspace program to get size of a partition where abstract file exists.

Example Program


package service1;
import java.io.File;

public class TotalSpace {
	public static void main(String[] args) {
		File f = null;
		long v;
		boolean bool = false;
		try {
			// create new file
			f = new File("d:/test.txt");
			// returns size of the partition named
			v = f.getTotalSpace();
			// true if the file path exists
			bool = f.exists();
			// if file exists
			if (bool) {
				// prints
				System.out.print("size: " + v);
			}
		} catch (Exception e) {
			// if any error occurs
			e.printStackTrace();
		}
	}
}

Output

size: 107375226880

Description

The java.io.File.getTotalSpace() method returns the size of the partition named by this abstract pathname.

Declaration

Following is the declaration for java.io.File.getTotalSpace() method:

public long getTotalSpace()

Parameters

  • Not Applicable.

Return Value

The method returns the size, in bytes, of the partition.

Exception

  • SecurityException — If a security manager has been installed and it denies RuntimePermission(“getFileSystemAttributes”)or its SecurityManager.checkRead(String) method denies read access to the file.

 

BACK

Filed in: Z-A All Java Codes

Comments are closed.