针对java.io.FileNotFoundException open failed: EACCES (Permission denied)出现的问题,是由于当前使用的安卓版本过高导致的,出现了文件访问失败。
1\解决方法是在AndroidMainfest中添加android:requestLegacyExternalStorage="true"
2\AndroidMainfest中添加
public void at_file()throws IOException { String sdcard=Environment.getDataDirectory().getPath().replace("data","sdcard"); String test_p1=sdcard+test_p; //File file = new File(Environment.getExternalStorageDirectory(), "a.txt"); File file=new File(sdcard,"a.txt"); InputStream inputStream = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { stringBuilder.append(line); } String fileContent = stringBuilder.toString(); System.out.println(fileContent); }
评论记录:
回复评论: