android的文件、目录操作(二)

 

android的文件、目录操作(二)  

2011-03-18 18:01:13|  分类: 工作学习 |  标签: |字号 订阅

  1. package otheri.common;  
  2.   
  3. import java.io.File;  
  4. import java.io.FileInputStream;  
  5. import java.io.FileOutputStream;  
  6. import java.io.IOException;  
  7. import java.io.InputStream;  
  8. import java.io.OutputStream;  
  9.   
  10. import otheri.io.Input;  
  11. import otheri.io.Output;  
  12. import android.content.Context;  
  13. import android.os.Environment;  
  14.   
  15. public class FileHelper {  
  16.     private Context context;  
  17.     private String SDPATH;  
  18.     private String FILESPATH;  
  19.   
  20.     public FileHelper(Context context) {  
  21.         this.context = context;  
  22.         SDPATH = Environment.getExternalStorageDirectory().getPath() + "\\";  
  23.         FILESPATH = this.context.getFilesDir().getPath() + "\\";  
  24.     }  
  25.   
  26.     /** 
  27.      * 在SD卡上创建文件 
  28.      *  
  29.      * @throws IOException 
  30.      */  
  31.     public File creatSDFile(String fileName) throws IOException {  
  32.         File file = new File(SDPATH + fileName);  
  33.         file.createNewFile();  
  34.         return file;  
  35.     }  
  36.   
  37.     /** 
  38.      * 删除SD卡上的文件 
  39.      *  
  40.      * @param fileName 
  41.      */  
  42.     public boolean delSDFile(String fileName) {  
  43.         File file = new File(SDPATH + fileName);  
  44.         if (file == null || !file.exists() || file.isDirectory())  
  45.             return false;  
  46.         file.delete();  
  47.         return true;  
  48.     }  
  49.   
  50.     /** 
  51.      * 在SD卡上创建目录 
  52.      *  
  53.      * @param dirName 
  54.      */  
  55.     public File creatSDDir(String dirName) {  
  56.         File dir = new File(SDPATH + dirName);  
  57.         dir.mkdir();  
  58.         return dir;  
  59.     }  
  60.   
  61.     /** 
  62.      * 删除SD卡上的目录 
  63.      *  
  64.      * @param dirName 
  65.      */  
  66.     public boolean delSDDir(String dirName) {  
  67.         File dir = new File(SDPATH + dirName);  
  68.         return delDir(dir);  
  69.     }  
  70.   
  71.     /** 
  72.      * 修改SD卡上的文件或目录名 
  73.      *  
  74.      * @param fileName 
  75.      */  
  76.     public boolean renameSDFile(String oldfileName, String newFileName) {  
  77.         File oleFile = new File(SDPATH + oldfileName);  
  78.         File newFile = new File(SDPATH + newFileName);  
  79.         return oleFile.renameTo(newFile);  
  80.     }  
  81.   
  82.     /** 
  83.      * 拷贝SD卡上的单个文件 
  84.      *  
  85.      * @param path 
  86.      * @throws IOException 
  87.      */  
  88.     public boolean copySDFileTo(String srcFileName, String destFileName)  
  89.             throws IOException {  
  90.         File srcFile = new File(SDPATH + srcFileName);  
  91.         File destFile = new File(SDPATH + destFileName);  
  92.         return copyFileTo(srcFile, destFile);  
  93.     }  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值