首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android:无法读取数据元数据

Android:无法读取数据元数据
EN

Stack Overflow用户
提问于 2017-06-12 09:39:59
回答 1查看 1.1K关注 0票数 0

我有dat文件,它是二进制file.It,目前在我的项目的原始文件夹中。我想在我的程序中使用这个文件。我希望将其复制到设备上的特定位置,但在执行该方法时,我将得到错误的“未能读取数据元数据”

以下是一种方法:

代码语言:javascript
复制
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();
    }


}

想法?谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-06-12 10:49:15

显然,还有另一种实现解决方案,即将其放在Asset文件夹中的.dat二进制文件中。

以下是实施情况:

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

对我来说很管用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44496185

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档