来自 http://blog.csdn.net/fenghome/article/details/5668598
android的文件操作要有权限:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
SD卡下的文件操作:
1、判断SD卡是否插入
Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
2、获得sd卡根目录
File skRoot = Environment.getExternalStorageDirectory();
私有目录下的文件操作:
1、获得私有根目录
File fileRoot = Context.getFilesDir()+"//";
文件夹或文件夹操作:
a、获得文件或文件夹的绝对路径和相对路径
String path = File.getPath();//相对
String path = File.getAbsoultePath();//绝对
b 、获得文件或文件夹的父目录
String parentPath = File.getParent();
c、获得文件或文件夹的名称:
String Name = File.getName();
2、建立文件或文件夹
File.mkDir(); //建立文件夹
File.createNewFile();//建立文件
3、判断是文件或文件夹
File.isDirectory();
4、列出文件夹下的所有文件和文件夹名
File[] files = File.listFiles();
5、修改文件夹和文件名
File.renameTo(dest);
6、删除文件夹或文件
File.delete();
Android路径大全:
Environment.getExternalStorageState
:mounted
Environment.getDownloadCacheDirectory().getPath()
:/cache
Environment.getDataDirectory().getPath()
:/data
Environment.getExternalStorageDirectory().getPath()
:/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getPath()
:/mnt/sdcard/Pictures
Environment.getRootDirectory().getPath()
:/system
Environment.getDownloadCacheDirectory().getAbsolutePath()
:/cache
Environment.getDataDirectory().getAbsolutePath()
:/data
Environment.getExternalStorageDirectory().getAbsolutePath()
:/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getAbsolutePath()
:/mnt/sdcard/Pictures
Environment.getRootDirectory().getAbsolutePath()
:/system
Environment.getExternalStorageState
:mounted
Environment.getDownloadCacheDirectory().getPath()
:/cache
Environment.getDataDirectory().getPath()
:/data
Environment.getExternalStorageDirectory().getPath()
:/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getPath()
:/mnt/sdcard/Pictures
Environment.getRootDirectory().getPath()
:/system
Environment.getDownloadCacheDirectory().getAbsolutePath()
:/cache
Environment.getDataDirectory().getAbsolutePath()
:/data
Environment.getExternalStorageDirectory().getAbsolutePath()
:/mnt/sdcard
Environment.getExternalStoragePublicDirectory().getAbsolutePath()
:/mnt/sdcard/Pictures
Environment.getRootDirectory().getAbsolutePath()
:/system`