android 文件权限被拒,android - 写入文件时,Android权限被拒绝 - 堆栈内存溢出

我说内部存储不是要保存安全数据,而是尝试保存一些图像或公共文件,而我正在尝试一切尝试,但它给我错误,我不知道该在内部存储中创建一个文件吗?为什么D:

码:

File file = new File(Environment.getDataDirectory() + File.separator

+ "test1111111.txt");

Log.e("ERROR", Environment.getDataDirectory() + File.separator

+ "testfile.txt");

try {

file.createNewFile();

} catch (IOException e) {

e.printStackTrace();

}

byte[] data1 = {

1, 1, 0, 0

};

// write the bytes in file

if (file.exists())

{

OutputStream fo = null;

try {

fo = new FileOutputStream(file);

} catch (FileNotFoundException e) {

e.printStackTrace();

}

try {

fo.write(data1);

} catch (IOException e) {

e.printStackTrace();

}

try {

fo.close();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("file created: " + file);

}

错误:

04-24 03:41:22.704 7797-7797/com.test.test W/dalvikvm﹕ VFY: unable to resolve virtual method 357: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;

04-24 03:41:22.744 7797-7797/com.test.test E/ERROR﹕ /data/testfile.txt

04-24 03:41:22.744 7797-7797/com.test.test W/System.err﹕ java.io.IOException: open failed: EACCES (Permission denied)

04-24 03:41:22.744 7797-7797/com.test.test W/System.err﹕ at java.io.File.createNewFile(File.java:940)

表现:

package="com.test.test" >

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

android:name=".MainActivity"

android:label="@string/app_name" >

在仿真器中工作正常,但是当我尝试使用手机时,却给我错误。 仿真器:

81e3e511fa0d45ddcff965ca38dca447.png

设备:它给我错误。

已编辑

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值