如何解决开放失败:ENOENT(没有这样的文件或目录)问题?

时间:2018-01-15 14:09:02

标签: android file google-api google-drive-api filepath

我正在上传文件以使用Google驱动器管理我的应用 我收到的问题如下。

  

java.io.FileNotFoundException:file:/android_asset/config.json:open failed:ENOENT(没有这样的文件或目录)

我的项目资产文件夹中有一个文件名config.json 我在SO上阅读了很多关于同一问题的帖子,但我找到的解决方案都没有对我有用。

以下是我上传文件的代码。

 try {
            File fileMetadata = new File();
            fileMetadata.setName("config.json");
            fileMetadata.setParents(Collections.singletonList("appDataFolder"));

            java.io.File filePath = new java.io.File("file:///android_asset/config.json");
            FileContent mediaContent = new FileContent("application/json", filePath);
            File file = mService.files().create(fileMetadata, mediaContent)
                    .setFields("id")
                    .execute();
            Log.d("File ID: ", file.getId()); // System.out.println("File ID: " + file.getId());
        } catch (IOException e) {
            Log.d("File ID: ", e.getMessage());
            e.printStackTrace();
        }

有谁知道为什么会出现这个问题以及如何解决它?

0 个答案:

没有答案