xuxiuxi
2017-07-10 d6119c2d7fe2f802dd224d77bf2d95eeeedb4526
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;
@@ -29,4 +31,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[]{};
    }
}