[Android Q&A, Help & Troubleshooting] NishaGowda:
In the below attached code , I am able to select file from internal storage using file picker, but unable to open the file for reading the file. code for reading the file is written, looks like its not picking the right path for opening the file, so throwing exception. Can anyone help me diagnose the issue.

package android.ble.internal_storage;

import android.Manifest;

import android.content.Context;

import android.content.Intent;

import android.content.pm.PackageManager;

import android.os.Bundle;

import android.app.Activity;

import android.view.View;

import android.widget.EditText;

import android.widget.Toast;

import androidx.core.app.ActivityCompat;

import androidx.core.content.ContextCompat;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.InputStreamReader;

import java.io.OutputStreamWriter;

public class MainActivity extends Activity {

private static final int PERMISSION_WRITE_STORAGE = 11;

private static final int PERMISSION_READ_EXTERNAL_STORAGE = 12;

private static final int CHOOSE_TXT_FROM_DEVICE = 1;

EditText textmsg;

static final int READ_BLOCK_SIZE = 100;

@override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

textmsg = (EditText) findViewById(R.id.editText1);

}

public void WriteBtn(View v) {

try {

FileOutputStream fileout = openFileOutput("mytextfile.txt", MODE_PRIVATE); //mytextfile.txt

OutputStreamWriter outputWriter = new OutputStreamWriter(fileout);

Context context = getApplicationContext();

String folder = context.getFilesDir().getAbsolutePath();

outputWriter.write(folder + " ");

outputWriter.write(textmsg.getText().toString());

outputWriter.close();

Toast.makeText(getBaseContext(), "File saved successfully!",

Toast.LENGTH_SHORT).show();

} catch (Exception e) {

e.printStackTrace();

}

}

@override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

if (requestCode == CHOOSE_TXT_FROM_DEVICE && resultCode == Activity.RESULT_OK) {

if (data != null) {

Read_from_file(data.getData().getPath());

}

}

}

public void ReadBtn(View v) {

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.addCategory(Intent.CATEGORY_OPENABLE);

intent.setType("*/*");

startActivityForResult(intent, CHOOSE_TXT_FROM_DEVICE);

}

public void Read_from_file(String file_path) {

File fileMedia = new File(file_path);

if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) !=

PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this,

new String[] {

Manifest.permission.WRITE_EXTERNAL_STORAGE

}, PERMISSION_WRITE_STORAGE);

}

if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) !=

PackageManager.PERMISSION_GRANTED) {

ActivityCompat.requestPermissions(this,

new String[] {

Manifest.permission.READ_EXTERNAL_STORAGE

}, PERMISSION_READ_EXTERNAL_STORAGE);

}

try {

FileInputStream fileIn = openFileInput(fileMedia.getName());

InputStreamReader InputRead = new InputStreamReader(fileIn);

char[] inputBuffer = new char[READ_BLOCK_SIZE];

String s = "";

int charRead;

while ((charRead = InputRead.read(inputBuffer)) > 0) {

String readstring = String.copyValueOf(inputBuffer, 0, charRead);

s += readstring;

}

InputRead.close();

textmsg.setText(s);

} catch (Exception e) {

e.printStackTrace();

}

}

}