Skip to content Skip to sidebar Skip to footer

Saving Public Files In Android But Folders Are Not Accessible By Pc

I am trying to create some public folders for my app to save some data. My goal is to create a main folder and a subfolder named based on the current date in order to save my data.

Solution 1:

I found a solution. I change the code to

Fileroot=newFile(Environment.getExternalStorageDirectory()+ "/Main folder/"+date);
        if (!root.exists()) {
            root.mkdirs();
        }
        myfile = newFile(root.getAbsolutePath(), sFileName);
        writer = newFileWriter(myfile);

The use of getExternalStorageDirectory works on all android versions unlike getExternalStoragePublicDirectory( Environment.DIRECTORY_DOCUMENTS)

Also the part from CommonsWare answer is necessary.

Solution 2:

Scan myfile, not root, and only after you have written to and closed your FileWriter.

Post a Comment for "Saving Public Files In Android But Folders Are Not Accessible By Pc"