读取文件中的机器人 - 文件权限被拒绝 [英] Read file in android - file permission denied
本文介绍了读取文件中的机器人 - 文件权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读取外部存储文件。我上传的文件在Eclipse DDMS存储/ SD卡(如下图所示)。但每当我试图读取,我得到了拒绝的权限的错误。有没有在我的文件权限什么问题?或者,我需要在manifest文件添加任何东西(我不是写在此刻什么)?
任何帮助将AP preciated。
code:
公共无效extimport(视图v){
的EditText xedittxt =(EditText上)findViewById(R.id.frmexttxt);
。字符串XEDIT = xedittxt.getText()的toString();
XEDIT = xedit.trim();
档案文件;
文件=新的文件(XEDIT);
StringBuilder的文本=新的StringBuilder();
Log.d(F确认,+ XEDIT);
尝试{
BR的BufferedReader =新的BufferedReader(新的FileReader(文件)); //此行会抛出错误
Log.d(F确认,F3); //此行从未被印
串线;
而((行= br.readLine())!= NULL){
text.append(线);
text.append('\\ n');
}
br.close();
resultView =(的TextView)findViewById(R.id.header);
resultView.setText(文本);
}
赶上(IOException异常五){
Log.d(文件打开错误,+ E);
Toast.makeText(getApplicationContext(),打开文件错误。,Toast.LENGTH_SHORT).show();
}
}
LogCat中:
11-19 00:21:54.252:D / F确认(5885):/storage/sdcard/mylibman.csv
11-19 00:21:54.272:D /文件打开错误(5885):java.io.FileNotFoundException:/storage/sdcard/mylibman.csv:打开失败:EACCES(权限被拒绝)
解决方案
请确保您已经添加到阅读清单档案中的外部存储的权限。
<使用许可权的android:NAME =android.permission.READ_EXTERNAL_STORAGE/>
I want to read file from external storage. I uploaded the file in Eclipse DDMS to storage/sdcard (image below). But whenever I tried to read, I got an error of permission denied. Is there any problem in my file permission? Or I need to add anything in manifest file (I am not writing anything at the moment)?
Any help will be appreciated.
Code:
public void extimport(View v){
EditText xedittxt = (EditText) findViewById(R.id.frmexttxt);
String xedit = xedittxt.getText().toString();
xedit = xedit.trim();
File file;
file = new File(xedit);
StringBuilder text = new StringBuilder();
Log.d("fcheck",""+xedit);
try {
BufferedReader br = new BufferedReader(new FileReader(file)); //THIS LINE THROWS ERROR
Log.d("fcheck","f3"); //This line never got printed
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
resultView = (TextView) findViewById(R.id.header);
resultView.setText(text);
}
catch (IOException e) {
Log.d("File open error",""+e);
Toast.makeText(getApplicationContext(), "Error opening the file.", Toast.LENGTH_SHORT).show();
}
}
LogCat:
11-19 00:21:54.252: D/fcheck(5885): /storage/sdcard/mylibman.csv
11-19 00:21:54.272: D/File open error(5885): java.io.FileNotFoundException: /storage/sdcard/mylibman.csv: open failed: EACCES (Permission denied)
解决方案
Make sure you have added the permission to read external storage in your manifest file.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
这篇关于读取文件中的机器人 - 文件权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文