0

I have dat file, which is binary file.It currently inside raw folder on my project. I want to use the file in my program. I want to copy it to certain location on the device but when executing the method, I am getting the error "Failed to read Data Meta Data"

Here is the method:

public void copyRawOnSdCard(){

    File sdcard = Environment.getExternalStorageDirectory();
    String targetPath = sdcard.getAbsolutePath() + File.separator + "shape_predictor_68_face_landmarks.dat";
    File file = new File(targetPath);
    if (!file.exists())
    {
        final ProgressDialog pd;    pd = ProgressDialog.show(this, "Copy Files for the First Time", "Please wait",
            true);
        pd.show();
        InputStream in = getResources().openRawResource(
                getResources().getIdentifier("shape_predictor_68_face_landmarks",
                        "raw", getPackageName()));
        FileOutputStream out = null;
        try {
            out = new FileOutputStream(targetPath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        byte[] buff = new byte[1024];
        int read = 0;

        try {
            while ((read = in.read(buff)) > 0) {
                out.write(buff, 0, read);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try{
                in.close();
            }catch (IOException e) {
                e.printStackTrace();
            }

            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        pd.cancel();
    }


}

Ideas? Thanks

1 Answers1

0

Apparently There is another implementation solution and that is to put it the .dat binary file in assets folder.

And here is the implementation:

https://stackoverflow.com/questions/4447477/how-to-copy-files-from-assets-folder-to-sdcard

And it worked for me.