Questions tagged [android-file]

Specifically the Android `File` class, but may also refer to the generic concept of files under the Android operating system

Specifically the Android File class, but may also refer to the generic concept of files under the Android operating system.

Use this tag if you have reason to believe your usage of files under Android causes the error your question is referring to.

1002 questions
820
votes
30 answers

android.os.FileUriExposedException: file:///storage/emulated/0/test.txt exposed beyond app through Intent.getData()

The app is crashing when I'm trying to open a file. It works below Android Nougat, but on Android Nougat it crashes. It only crashes when I try to open a file from the SD card, not from the system partition. Some permission problem? Sample…
Thomas Vos
  • 11,085
  • 4
  • 24
  • 63
323
votes
14 answers

Show Image View from file path?

I need to show an image by using the file name only, not from the resource id. ImageView imgView = new ImageView(this); imgView.setBackgroundResource(R.drawable.img1); I have the image img1 in the drawable folder. I wish to show that image from the…
Alex
  • 14,719
  • 6
  • 20
  • 19
190
votes
14 answers

How to create directory automatically on SD card

I'm trying to save my file to the following location FileOutputStream fos = new FileOutputStream("/sdcard/Wallpaper/"+fileName); but I'm getting the exception java.io.FileNotFoundException However, when I put the path as "/sdcard/" it works. Now I'm…
Kshitij Aggarwal
  • 4,960
  • 5
  • 32
  • 41
131
votes
3 answers

Difference between mkdir() and mkdirs() in java for java.io.File

Can anyone tell me the difference between these two methods: file.mkdir() file.mkdirs()
Krishna Kankal
  • 1,493
  • 2
  • 9
  • 4
60
votes
8 answers

Trying to create a file in Android: open failed: EROFS (Read-only file system)

This line: final FileOutputStream outputStream = new FileOutputStream(name); results in a FileNotFoundException with the message being /2ozjfFQzwv: open failed: EROFS (Read-only file system) where "2ozjfFQzwv" is what I passed as the name of the…
Drew
  • 9,858
  • 10
  • 52
  • 88
59
votes
3 answers

File.createTempFile() VS new File()

In my app I added the possibility to add and save pictures for everyday day, represented by a Fragment. In order to save the picture on the SD card, I currently use the function File.createTempFile: File imageFile =…
Yoann Hercouet
  • 17,272
  • 4
  • 56
  • 80
55
votes
5 answers

Database won't remove when uninstall the Android Application

I have two major questions. Database won't delete when uninstall app. Downloaded files won't delete while unstable the app. There is a database in my android application. I create it by java class as follows. public DataBaseHelper(Context…
KZoNE
  • 898
  • 1
  • 11
  • 23
53
votes
3 answers

List all the files from all the folder in a single list

Hi I am looking for the solution to list all the files from root/Android device. Suppose there are 3 folder inside root directory,but I want to display all the files in all of these folder in a single list.. Now If am using File f=new…
Kanika
  • 10,328
  • 17
  • 58
  • 77
43
votes
8 answers

Where are Android Emulator Image Stored?

On the emulator, I downloaded an image from Google. I can find the image on the emulator, but I have no idea what the file location of the image is. To debug my app I need to know where that image is. How can I get the full path of the image?
Get Off My Lawn
  • 27,770
  • 29
  • 134
  • 260
41
votes
4 answers

Create and Share a File from Internal Storage

My goal is to create a XML file on internal storage and then send it through the share Intent. I'm able to create a XML file using this code FileOutputStream outputStream = context.openFileOutput(fileName, Context.MODE_WORLD_READABLE); PrintStream…
Kirk
  • 15,831
  • 19
  • 73
  • 105
40
votes
4 answers

Load a file from external storage to Inputstream

i have a video file in my external directory. how can i load it to inputstream variable. For the time being i am reading file in the res/raw folder but i want to read it from the sdcard. also i dont know about the name of the file but its path will…
Talha Malik
  • 1,392
  • 3
  • 19
  • 41
40
votes
5 answers

Save bitmap to file function

I'm trying to save a bitmap to file and a specific directly using a function I've created. It's not working. It crashes after bitmap.compress part (before here3). File dir = new File(filepath); if(!dir.exists())dir.mkdirs(); File file…
Oliver Dixon
  • 6,069
  • 5
  • 52
  • 82
39
votes
15 answers

Android: mkdirs()/mkdir() on external storage returns false

I'm driven crazy with this: Log.d("STATE", Environment.getExternalStorageState()); File f = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "work_data"); Log.d("PATH", f.getAbsolutePath()); if (!f.exists()) { …
MHM
  • 690
  • 1
  • 7
  • 17
39
votes
16 answers

How to access /storage/emulated/0/

I have written a code to record audio and save it to below file location. private String getFilename() { String filepath = Environment.getExternalStorageDirectory().getPath(); File file = new File(filepath, AUDIO_RECORDER_FOLDER); if…
nerdy_me
  • 401
  • 1
  • 4
  • 7
37
votes
6 answers

Simple mediaplayer play mp3 from file path?

I have a very simple mediaplayer that play background. It calls file from the apk, but I want it to play from any directory like as music or sdcard. Here are my codes: private MediaPlayer mpintro; . . mpintro = MediaPlayer.create(this,…
John simit
  • 1,205
  • 2
  • 11
  • 13
1
2 3
66 67