我得到了

开放失败:EACCES (Permission denied)

在线OutputStream myOutput = new FileOutputStream(outFileName);

我判断了根部,我试了android.permission.WRITE_EXTERNAL_STORAGE.

我如何解决这个问题?

try {
    InputStream myInput;

    myInput = getAssets().open("XXX.db");

    // Path to the just created empty db
    String outFileName = "/data/data/XX/databases/"
            + "XXX.db";

    // Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);

    // Transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }

    // Close the streams
    myOutput.flush();
    myOutput.close();
    myInput.close();
    buffer = null;
    outFileName = null;
}
catch (IOException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

推荐答案

我也有同样的问题...<uses-permission人的位置不对.这是对的:

 <manifest>
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        ...
        <application>
            ...
            <activity> 
                ...
            </activity>
        </application>
    </manifest> 

uses-permission标签必须在application标签之外.

Android相关问答推荐

Android Kotlin DSL Gradle找不到自定义存储库中的依赖项

在Kotlin Jetpack Compose中点击按钮后启动另一个Android应用程序

我正在创建一个简单的连接四个游戏,我需要一个弹出式窗口当你赢了

第一次使用onBackPressed()、NavigateUp()加载时MapView崩溃

设置文本 colored颜色 动画时如何减少重新组合?

为什么我的 APK 中包含来自旧版 Android 支持库的类?

Gradle在我的Android Compose项目中继续推广依赖版本

如何删除房间数据库?

Jetpack Compose - 在屏幕外偏移绘制形状并使用非常大的尺寸

在 Material 3 TopAppBar 代码的哪个位置定义了填充?

为什么@PrimaryKey val id: Int? = null 在创建 Room 实体时有效吗?

系统导航栏在某些场景下应用了深色效果

我们也可以或应该对主要小部件使用预览 compose 功能吗?

android xml底部空间大

react 从输入中找到路径'lib/arm64-v8a/libfbjni.so'的本机2个文件

我的观点在jetpack compose中相互重叠

Compose `Icons.Outlined.Star` 没有概述

如何在 MAUI 项目中包含每个平台的现有 C++ 库?

如何在 Android Studio 中使用 Github Copilot?

在 Compose 中使用 DeepLink 会导致无法向后导航