I try to make a program that will open the desired file in this way: In one field, the user enters the full path to the file, and when you click on the button, the program reads this path and creates an object of the FileReader class with this path and reads text from this file. The problem is that FileNotFoundException is always thrown. How to fix?

  • Maybe you do not have the necessary permissions in the manifest or you did not programmatically request them from the user on version 6 of the android? - Yuriy SPb

2 answers 2

In the AndroidManifest.xml file, you need to enter such lines to gain access to the reading <manifest ...> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> ... </manifest>

    To avoid FileNotFoundException, first check whether the file really exists at the specified path. You can do this using the exists () method of the File class object .

     File file = new File(filePath); if (file.exists()) { // открываем файл для чтения }