# Android 2.3中的java.io.File类新增功能

**URL:** <https://www.isharkfly.com/t/android-2-3-java-io-file/7504>\
**Category:** 程序语言\
**Created:** [November 30, 2012, 3:11pm UTC](https://www.isharkfly.com/t/android-2-3-java-io-file/7504 "2012-11-30T15:11:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [November 30, 2012, 3:11pm UTC](https://www.isharkfly.com/t/android-2-3-java-io-file/7504/1 "2012-11-30T15:11:47Z")

</div>

对于Android 2.3来说原始Sun公司的java.io.File包中的内容也有了改进，File类在API Level为9时多出了很多新特性，比较实用的有:

public long getFreeSpace () 返回这个分区包含这个路径的剩余空间，如果返回0则表示不存在，下面为SDK原文

Returns the number of free bytes on the partition containing this path. Returns 0 if this path does not exist. Note that this is likely to be an optimistic over-estimate and should not be taken as a guarantee your application can actually write this many bytes

public long getTotalSpace () 返回这个分区包含这个路径的总共字节，如果返回0则表示不存在，下面为SDK原文

Returns the total size in bytes of the partition containing this path. Returns 0 if this path does not exist

同时还有一些和权限相关的API，感兴趣的网友可以在Android 2.3的SDK文档中找到，详细如下

public boolean setExecutable (boolean executable)

public boolean setReadable (boolean readable)

public boolean setWritable (boolean writable, boolean ownerOnly)
