xuxiuxi
2017-07-12 8eba4786474eb6ec2861f37bc628d8d5f0aa0d96
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java
@@ -3,6 +3,8 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.RandomAccessFile;
import cn.com.basic.face.base.MainActivity;
@@ -11,6 +13,9 @@
    public static File writeToFile(String fileName, byte[] fileBytes) {
        try {
            if (fileBytes == null) {
                fileBytes = new byte[]{};
            }
            String dir = MainActivity.getInstance().getFilesDir().getAbsolutePath();
            File file = new File(dir, fileName);
@@ -29,4 +34,32 @@
        return null;
    }
    public static byte[] readFile(File file) {
        // Open file
        RandomAccessFile f = null;
        try {
            f = new RandomAccessFile(file, "r");
            // Get and check length
            long longlength = f.length();
            int length = (int) longlength;
            if (length != longlength)
                throw new IOException("File size >= 2 GB");
            // Read file and return data
            byte[] data = new byte[length];
            f.readFully(data);
            return data;
        } catch (Exception e){
            e.printStackTrace();
        } finally {
            try {
                f.close();
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
        return new byte[]{};
    }
}