我想在程序文件夹下写个配置文件,同样的代码,之前运行都没问题,今天怎么也创建不起文件,提示没有权限,请问大侠们有谁知道是怎么回事,谢谢,代码如下:
FloatWindowService.AppPath = getApplicationContext().getFilesDir()
.getAbsolutePath();
flipper_getdata = (ViewFlipper) findViewById(R.id.flipper_getdata);
bar = (ProgressBar) findViewById(R.id.progressBar1);
// 在这里创建一个设置文件
// 查看目录是否存在
File file = new File(FloatWindowService.AppPath);
FloatWindowService.AppPath = FloatWindowService.AppPath
+ "/set_data.tyzj";
// 查看设置文件是否存在
file = new File(FloatWindowService.AppPath);
if (!file.exists())// 如果不存在则创建
{//创建文件
try
{file.createNewFile();//这句出错,e.getMessage()是"Permission denied"
Log.v("消息","文件已成功创建");//没执行到这句
FloatWindowService.SetFileWrite = openFileOutput(
"set_data.tyzj", MODE_PRIVATE);
------解决方案--------------------
Manifest里加上权限试试
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
------解决方案--------------------
查看一下权限加了没
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
然后打开android模拟器检查一下这个模拟器在创建的时候sd卡有没有创建