WEB开发网
开发学院手机开发Android 开发 Android 处理txt文件类FileUtils 利用java反射机制... 阅读

Android 处理txt文件类FileUtils 利用java反射机制访问非sdk类和函数

 2010-09-10 00:59:00 来源:WEB开发网   
核心提示:Android系统内部提供了一个不错的txt文本读写类,但目前并没有公开提供给标准的SDK,Android 处理txt文件类FileUtils 利用java反射机制访问非sdk类和函数,FileUtils类的源代码如下,可以很好的操作Linux下的文本文件

Android系统内部提供了一个不错的txt文本读写类,但目前并没有公开提供给标准的SDK,FileUtils类的源代码如下,可以很好的操作Linux下的文本文件。

public class FileUtils

{

public static final int S_IRWXU = 00700;

public static final int S_IRUSR = 00400;

public static final int S_IWUSR = 00200;

public static final int S_IXUSR = 00100;

public static final int S_IRWXG = 00070;

public static final int S_IRGRP = 00040;

public static final int S_IWGRP = 00020;

public static final int S_IXGRP = 00010;

public static final int S_IRWXO = 00007;

public static final int S_IROTH = 00004;

public static final int S_IWOTH = 00002;

public static final int S_IXOTH = 00001;

public static final class FileStatus {

public int dev;

public int ino;

public int mode;

public int nlink;

public int uid;

public int gid;

public int rdev;

public long size;

public int blksize;

public long blocks;

public long atime;

public long mtime;

public long ctime;

}

public static native boolean getFileStatus (String path, FileStatus status);

private static final Pattern SAFE_FILENAME_PATTERN = Pattern.compile("[\w%+,./=_-]+");

public static boolean copyFile(File srcFile, File destFile) {

boolean result = false;

try {

InputStream in = new FileInputStream(srcFile);

try {

result = copyToFile(in, destFile);

} finally {

in.close();

}

} catch (IOException e) {

result = false;

}

return result;

}

public static boolean copyToFile (InputStream inputStream, File destFile) {

1 2 3 4 5  下一页

Tags:Android 处理 txt

编辑录入:coldstar [复制链接] [打 印]
赞助商链接