java.io.FileNotFoundException: /storage/emulated/0/Notes/fact50Result.txt: open failed ENOENT (No such file or directory)
As discussed in the comments, you need to request permissions at runtime to allow your app to write to external storage. You can check if your app has the permission already by using checkSelfPermission()
. For example:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
// Do the file write
} else {
// Request permission from the user
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 0);
...
}
In order to handle this permission request, you'll also need to implement onRequestPermissionsResult()
from OnRequestPermissionsResultCallback
, for example:
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case 0:
// Re-attempt file write
}
}
Read the documentation for full information.
Android - java.io.FileNotFoundException: /storage/emulated/0/Notes/File.txt: open failed: ENOENT (No such file or directory)
Problem SolvedI used SharedPreferences of Android.
I stored the data in MainActivity and take in in my Class as follow:
MainActivity
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("string_id", InputString); //InputString: from the EditText
editor.commit();In my Class to get my data
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String data = prefs.getString("string_id", "no id"); //no id: default value
java.io.FileNotFoundException caught when processing request: /document/raw:/storage/emulated/0/Download/mypdf.pdf (No such file or directory)
I've just fixed a NumberFormat
crash in code snippet from this brilliant answer. You can find my answer with code here.
Related Topics
How to Remove the Decimal Part If It Is Only 0
A Method to Check If a Collection or Map Is Empty or Null
Error: Incompatible Types: Int[][] Cannot Be Converted to Int
How to Avoid Nullpointerexception With an Empty Cell Using Poi
How to Pass or Send Data from Recyclerview Adapter to Fragment
Mapstruct: Map List of Objects, When Object Is Mapped from Two Objects
What Is the Most Elegant Way to Check If All Values in a Boolean Array Are True
Error: Java: Invalid Target Release: 11 - Intellij Idea
Selenium Webdriver: Clicking on Elements Within an Svg Using Xpath
Largest and Smallest Integer - Exercise from Deitel'S Java Book
How to Download a Pdf File in Chrome Using Selenium Webdriver
Illegal Character When Trying to Compile Java Code
Wrong Answer in Task - Mistake in Algorithm
Java.Lang.Noclassdeffounderror: Lorg/Apache/Logging/Log4J/Logger; But the Artifact Exists
Tomcat Server Error - Port 8080 Already in Use