There is a code that saves data to a file in the application directory.

try { OutputStream outputStream = openFileOutput("nameOfFile.txt", 0); OutputStreamWriter osw = new OutputStreamWriter(outputStream); osw.write("data"); osw.close(); } catch (Throwable t) { Toast.makeText(getApplicationContext(), "Exception: " + t.toString(), Toast.LENGTH_SHORT).show(); } 

It is necessary that the program check the presence of the Folder folder in the application directory, in its absence create a folder, and then save the file to the Folder folder in the application directory.
I found manuals for creating a folder along a specific path (to a memory card), but it is not clear to me which path to point to for the application storage.

  • Check for the existence of a file and create a folder when there is no Context c = getApplicationContext (); File file = new File (c.getFilesDir (), "/ Folder"); if (file.exists ()) {Log.d (TAG, "exists"); } else {Log.d (TAG, "not exists"); file.mkdir (); } - arkada38

2 answers 2

So where is the question? What is the problem? Here's a link to you about how to create folders . Before asking questions, it would be nice to teach Java.

for more , and read about the methods. And here is how folders are created in android. Learn mate part.

    but it is not clear to me which path should be specified for the application storage.

    It's simple. A link to the directory in the application directory can be obtained by calling the method

     Context.getFilesDir() 

    Further along the path laid by the nervous @argamidon . :)