android的文件、目录操作(三)
2011-03-18 18:02:26| 分类: 工作学习 | 标签: |字号大中小 订阅
-
/** - * 拷贝SD卡上指定目录的所有文件
- *
- * @param srcDirName
- * @param destDirName
- * @return
- * @throws IOException
- */
- public boolean copySDFilesTo(String srcDirName, String destDirName)
- throws IOException {
- File srcDir = new File(SDPATH + srcDirName);
- File destDir = new File(SDPATH + destDirName);
- return copyFilesTo(srcDir, destDir);
- }
- /**
- * 移动SD卡上的单个文件
- *
- * @param srcFileName
- * @param destFileName
- * @return
- * @throws IOException
- */
- public boolean moveSDFileTo(String srcFileName, String destFileName)
- throws IOException {
- File srcFile = new File(SDPATH + srcFileName);
- File destFile = new File(SDPATH + destFileName);
- return moveFileTo(srcFile, destFile);
- }
- /**
- * 移动SD卡上的指定目录的所有文件
- *
- * @param srcDirName
- * @param destDirName
- * @return
- * @throws IOException
- */
- public boolean moveSDFilesTo(String srcDirName, String destDirName)
- throws IOException {
- File srcDir = new File(SDPATH + srcDirName);
- File destDir = new File(SDPATH + destDirName);
- return moveFilesTo(srcDir, destDir);
- }
- /*
- * 将文件写入sd卡。如:writeSDFile("test.txt");
- */
- public Output writeSDFile(String fileName) throws IOException {
- File file = new File(SDPATH + fileName);
- FileOutputStream fos = new FileOutputStream(file);
- return new Output(fos);
- }
- /*
- * 在原有文件上继续写文件。如:appendSDFile("test.txt");
- */
- public Output appendSDFile(String fileName) throws IOException {
- File file = new File(SDPATH + fileName);
- FileOutputStream fos = new FileOutputStream(file, true);
- return new Output(fos);
- }
- /*
- * 从SD卡读取文件。如:readSDFile("test.txt");
- */
- public Input readSDFile(String fileName) throws IOException {
- File file = new File(SDPATH + fileName);
- FileInputStream fis = new FileInputStream(file);
- return new Input(fis);
- }
- /**
- * 建立私有文件
- *
- * @param fileName
- * @return
- * @throws IOException
- */
- public File creatDataFile(String fileName) throws IOException {
- File file = new File(FILESPATH + fileName);
- file.createNewFile();
- return file;
- }
- /**
- * 建立私有目录
- *
- * @param dirName
- * @return
- */
- public File creatDataDir(String dirName) {
- File dir = new File(FILESPATH + dirName);
- dir.mkdir();
- return dir;
- }
本文介绍如何在Android设备的SD卡上进行文件和目录的复制、移动以及文件的写入、追加读取等操作,包括创建私有文件、目录的方法。

被折叠的 条评论
为什么被折叠?



