【发布时间】:2016-02-27 00:41:18
【问题描述】:
我正在创建一个应用程序,我想在其中读取 sd 卡中的文件,然后使用另一个文件中的信息写入另一个文件。尝试读取文件时出现以下错误: System.UnauthorizedAccessException: Access to the path 'sdcard/android/data/App1.App1/files/' is denied.
读取功能:
private string ReadFile(string fileName)
{
var path = "sdcard/android/data/App1.App1/files/";
var filePath = Path.Combine(path.ToString(), fileName);
string text = File.ReadAllText(path.ToString());
return text;
}
Android 清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="App1.App1" android:versionCode="1" android:versionName="1.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application android:label="Scout" android:icon="@drawable/Icon" android:theme="@style/CustomActionBarTheme"></application>
</manifest>
【问题讨论】:
-
请查看本教程developer.xamarin.com/samples/monodroid/StorageClient但这仅用于存储在内部存储器中。
标签: android xamarin android-4.4-kitkat android-sdcard readfile