Android,无法写入SD卡

时间:2014-10-05 22:02:50

标签: android android-sdcard

我一直在墙上撞了一会儿。我无法理解为什么这不是写入SD卡,如果是,那么它在哪里?

当我运行时,路径显示/ storage / sdcard0     的System.out.println(sdcard.getAbsolutePath());

File sdcard = Environment.getExternalStorageDirectory();
    File dir = new File(sdcard.getAbsolutePath() + "dirname");
    dir.mkdir();
    File file = new File(dir, "filename.txt");
    FileOutputStream outStream;
    try {
        outStream = new FileOutputStream(file);
        String data = "CONTENT";
        outStream.write(data.getBytes());
        outStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

我的清单里面有许可,我很确定它在正确的地方

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testing_pdf_processing"
android:versionCode="1"
android:versionName="1.0" >

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="21" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

</application>

请!!任何帮助都会非常感激,因为我根本无法解决这个问题。

0 个答案:

没有答案
相关问题