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.

1038 questions
912
votes
27 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
  • 12,271
  • 5
  • 33
  • 71
348
votes
15 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
  • 16,375
  • 7
  • 22
  • 19
194
votes
13 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
  • 5,287
  • 5
  • 34
  • 41
143
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,621
  • 2
  • 10
  • 4
65
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
  • 12,578
  • 11
  • 58
  • 98
63
votes
4 answers

File.createTempFile() vs. new File()

In order to save a picture on the SD card, I currently use the function File.createTempFile: File imageFile = File.createTempFile(imageFileName, MyApplication.JPEG_FILE_SUFFIX, MyApplication.getAlbumDir()); I actually also tried with the standard…
Yoann Hercouet
  • 17,894
  • 5
  • 58
  • 85
61
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
  • 1,249
  • 1
  • 16
  • 27
61
votes
8 answers

Where are Android Emulator Images 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
  • 34,175
  • 38
  • 176
  • 338
54
votes
3 answers

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

I am looking for the solution to list all the files from root/Android device. Suppose there are three folders inside the root directory, but I want to display all the files in all of these folders in a single list... Now if am using File f = new…
Kanika
  • 10,648
  • 18
  • 61
  • 81
47
votes
16 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
  • 854
  • 1
  • 9
  • 17
47
votes
8 answers

Implementing a File Picker in Android and copying the selected file to another location

I'm trying to implement a File Picker in my Android project. What I've been able to do so far is : Intent chooseFile; Intent intent; chooseFile = new Intent(Intent.ACTION_GET_CONTENT); chooseFile.setType("*/*"); intent =…
47
votes
6 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
  • 7,012
  • 5
  • 61
  • 95
45
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,509
  • 3
  • 22
  • 44
45
votes
5 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
  • 16,182
  • 20
  • 80
  • 112
44
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
  • 451
  • 1
  • 5
  • 7
1
2 3
69 70