JDK-4057701 : Need way to find free disk space
  • Type: Enhancement
  • Status: Closed
  • Resolution: Fixed
  • Component: core-libs
  • Sub-Component: java.io
  • Priority: P3
  • Affected Version:
    1.1.1,1.1.3,1.1.5,1.2.1,1.3.0,1.3.1,1.4.0,1.4.1,1.4.2 1.1.1,1.1.3,1.1.5,1.2.1,1.3.0,1.3.1,1.4.0,1.4.1,1.4.2
  • OS:
    generic,solaris_2.5.1,solaris_2.6,solaris_9,windows_95,windows_nt,windows_2000 generic,solaris_2.5.1,solaris_2.6,solaris_9,windows_95,windows_nt,windows_2000
  • CPU: generic,x86,sparc
  • Submit Date: 1997-06-09
  • Updated Date: 2017-05-16
  • Resolved Date: 2005-06-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b39Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
Name: mc57594			Date: 06/09/97


The only way to find free disk space appears to be by a 'guess'
algorithm that attempts to create different file sizes...not 
acceptable.

======================================================================

Name: krT82822			Date: 04/13/99


Please add someting like statfs() or GetFreeSpace(), that 
allows to determine number of total, used and free blocks 
on a filesystem to java.io.File.
My program could be 100% Java, is this is solved.
======================================================================

Name: krT82822			Date: 08/26/99


Please fix bug ID 4071324 in time for the 1.3 fcs release.
I know its in the database but some bugs just seem to slip by each release.

Thanks,
James

8/26/99 eval1127@eng -- (dupe of 4057701)
(Review ID: 94446)
======================================================================

Name: rmT116609			Date: 08/26/2002


 DESCRIPTION OF THE PROBLEM :
There is no way to determine free disk space in a platform-independant way.

For each platform there exist a simple way to determine free disk space (or user-dependant quota) - but there is no api function in java available to
use this required and often requested feature.

(Review ID: 163627)
======================================================================1
###@###.### 2004-02-04
###@###.### 10/15/04 20:41 GMT

Comments
SUGGESTED FIX An initial pass at the spec: New methods in File: /* -- Disk usage -- */ /** * Returns the size of the partition <a href="#partName>named</a> by this * abstract pathname. * * @return The size, in bytes, of the partition or <tt>0L</tt> if this * abstract pathname does not name a partition * * @throws SecurityException * If a security manager has been installed and it denies * {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt> * * @since 1.6 */ public long getTotalSpace() {} /** * Returns the number of unallocated bytes in the partition named by this * abstract path name. * * <p> The returned number of unallocated bytes is a hint, but not * a guarantee, that it is possible to use most or any of these * bytes. The number of unallocated bytes is most likely to be * accurate immediately after this call. It is likely to be made * inaccurate by any external I/O operations including those made * on the system outside of this virtual machine. This method * makes no guarantee that write operations to this file system * will succeed. * * @return The number of unallocated bytes on the partition <tt>0L</tt> * if the abstract pathname does not name a partition. This * value will be less than or equal to the total file system size * returned by {@link #getTotalSpace}. * * @throws SecurityException * If a security manager has been installed and it denies * {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt> * * @since 1.6 */ public long getFreeSpace() {} /** * Returns the number of bytes available to this virtual machine on the * partition named by this abstract pathname. When possible, this method * checks for write permissions and other operating system restrictions * and will therefore usually provide a more accurate estimate of how much * new data can actually be written than {@link #getFreeSpace}. * * <p> The returned number of available bytes is a hint, but not a * guarantee, that it is possible to use most or any of these bytes. The * number of unallocated bytes is most likely to be accurate immediately * after this call. It is likely to be made inaccurate by any external * I/O operations including those made on the system outside of this * virtual machine. This method makes no guarantee that write operations * to this file system will succeed. * * @return The number of available bytes on the partition or <tt>0L</tt> * if the abstract pathname does not name a partition. On * systems where this information is not available, this method * will be equivalent to a call to {@link #getFreeSpace}. * * @throws SecurityException * If a security manager has been installed and it denies * {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt> * * @since 1.6 */ public long getUsableSpace() {} RuntimePermission.java: *************** *** 186,191 **** --- 186,201 ---- * </tr> * * <tr> + * <td>getFileSystemAttributes</td> + * <td>Retrieval of file system attributes</td> + * <td>This allows code to obtain file system information such as disk usage + * or disk space available to the caller. This is potentially dangerous + * because it discloses information about the system hardware + * configuration and some information about the caller's privilege to + * write files.</td> + * </tr> + * + * <tr> * <td>readFileDescriptor</td> * <td>Reading of file descriptors</td> * <td>This would allow code to read the particular file associated ###@###.### 2005-03-02 23:19:58 GMT
2005-03-02

EVALUATION A simple method or two for determining free disk space will be added to the java.io.File class in Mustang, which is scheduled to ship in mid-2006. ###@###.### 2005-1-28 21:40:10 GMT Resolution of this request is considered a high priority for Mustang. Active development on this feature has been in progress for the past several months. I expect that we will complete this work within the next couple of months. These methods will be in Mustang-beta. ###@###.### 2005-03-01 21:30:38 GMT
2005-03-01

WORK AROUND Name: mc57594 Date: 06/09/97 ======================================================================
2004-10-02