gpt4 book ai didi

java - Android:将 tar 文件从 Assets 复制到 sdcard - IOException

转载 作者:行者123 更新时间:2023-11-29 21:17:54 26 4
gpt4 key购买 nike

我正在尝试将 .tar 文件从 android Assets 复制到 sdcard,但在复制文件时出现 IOException。我正在使用前一个线程中的代码 How to copy files from 'assets' folder to sdcard?

这是 LogCat 文件。我在 ASyncTask 中执行所有这些操作,但我也在主 UI 线程上尝试过,但仍然出现此异常。

01-11 06:51:49.925: E/tag(3881): Failed to copy asset file: temp.tar
01-11 06:51:49.925: E/tag(3881): java.io.IOException
01-11 06:51:49.925: E/tag(3881): at android.content.res.AssetManager.readAsset(Native Method)
01-11 06:51:49.925: E/tag(3881): at android.content.res.AssetManager.access$700(AssetManager.java:36)
01-11 06:51:49.925: E/tag(3881): at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:571)
01-11 06:51:49.925: E/tag(3881): at com.example.apptest.MainActivity.copyFile(MainActivity.java:130)
01-11 06:51:49.925: E/tag(3881): at com.example.apptest.MainActivity.copyAssets(MainActivity.java:116)
01-11 06:51:49.925: E/tag(3881): at com.example.apptest.MainActivity.access$0(MainActivity.java:97)
01-11 06:51:49.925: E/tag(3881): at com.example.apptest.MainActivity$1.doInBackground(MainActivity.java:32)
01-11 06:51:49.925: E/tag(3881): at com.example.apptest.MyASyncTask.doInBackground(MyASyncTask.java:1)
01-11 06:51:49.925: E/tag(3881): at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-11 06:51:49.925: E/tag(3881): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
01-11 06:51:49.925: E/tag(3881): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
01-11 06:51:49.925: E/tag(3881): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
01-11 06:51:49.925: E/tag(3881): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
01-11 06:51:49.925: E/tag(3881): at java.lang.Thread.run(Thread.java:1096)

最佳答案

您是否已在 list 中授予权限。

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

因为写东西到sd需要权限

关于java - Android:将 tar 文件从 Assets 复制到 sdcard - IOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21059761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com