Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Creating a folder in the data/data/pkg/files directory

Referencing this question:

How to create files hierarchy in Androids '/data/data/pkg/files' directory?

What kind of a solution is there to this problem using the built in standard Java libraries, how do I navigate to the data/data/pkg directory and create folders and files in there? Maybe using some of the Android calls where possible?

When a user uses my app I wish to save any files associated with that user in a folder pkg/files/username, so that I can easily read these folders later. My other option is include the username in the filename but this isn't a very suitable and clean method in my opinion.

like image 284
Tim Avatar asked Mar 30 '11 13:03

Tim


People also ask

What is data folder in Android folder?

The application data folder is a special hidden folder that your app can use to store application-specific data, such as configuration files. The application data folder is automatically created when you attempt to create a file in it. Use this folder to store any files that the user shouldn't directly interact with.


1 Answers

getContext().getDir() method is your friend

File dir = ctx.getDir("my_sub_dir", Context.MODE_PRIVATE);
File newfile = new File(topDirFile.getAbsolutePath() + File.separator + "new_file_name");
newfile.createNewFile();
BufferedOutputStream fout = new BufferedOutputStream(new FileOutputStream(newfile), 16 * 1024);
like image 53
reflog Avatar answered Sep 27 '22 18:09

reflog