There is a need to download several mp3 files to your phone. These files should be used by the application. I initially tried to add an mp3 file to assert. I could not overcome this problem quickly. Yes, and the files must be downloaded already after installing the application. Need to upload files to the internal memory of the phone.

Tell me how to be. Tried to create an arbitrary file.

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter( openFileOutput(FILENAME, MODE_APPEND))); bw.write("Содержимое файла"); bw.close(); 

The file is being created, but I cannot find it in ES Explorer on the device.

  • 2
    mp3 files in res/raw/ lay down - pavlofff
  • @pavlofff res/raw/ yes, and did for the pre-installed file. Correct if I am mistaken, as far as I understand res/raw/ used just for pre-installed files (files that are an integral part of the application). I have a need to allow the user to download the necessary files for the application to use - x555xx
  • Yes, that's right, the / res / raw / directory is for static data only, it can only be read, but not edited or added there. Like all other directories within the project (and in the end. Apk), however. - pavlofff
  • @pavlofff and how to deal with external files, tell me. - x555xx

1 answer 1

You can use this way to handle application files (files that the application creates or downloads) to read and create them.

 String path = context.getFilesDir().getAbsolutePath(); File file = new File(path + "/" + fileName); 

Further this file can be opened for both Input and Output.

  • or I misunderstand something (enlighten) or formulate the question in the wrong way. File names and their number will be known only after installing the application. The file location directory is assumed either arbitrarily arbitrary (created by the user) or some kind of pre-created by the application. - x555xx
  • My version offers the opportunity to work with files that were created in the internal storage of the application. Those. when you install an application, it creates a folder in which it can store all its created or downloaded files. - strevg
  • Yes, I understood that. but I have a slightly different problem. The picture does not add up, how to create an application directory in which the user will place the files. (or the user himself will create a directory and point it to the application). - x555xx
  • I can’t even find the file that the application creates by name (ES Explorer in root mode and displaying hidden files, tried to find it through the search) - x555xx
  • one
    And if you need to be able to create your own folders and read them later, then you can do them like this: stackoverflow.com/questions/17794974/create-folder-in-android - strevg