Reputation: 2287
/data directory in android is empty. I have installed a few applications and i also wrote code to create a file in /data/Myapp directory ,
I have these lines in OnCreate method , but i dont see any files in /data directory after running the program.
File fileDir = getFilesDir();
String filedir=fileDir.toString();
Log.v("TEST","FILEDIR--->"+filedir);
//output i got is FILEDIR--->/data/data/com.android.Test/files
String strNewFileName = "test1.txt";
String strFileContents = " MY FIRST FILE CREATION PRGM";
File newFile = new File(fileDir, strNewFileName);
try{
boolean filestat = newFile.createNewFile();
Log.v("TEST"," CREATE FILE =>"+ filestat);
//output is CREATE FILE =>true indicating success
FileOutputStream fo =
new FileOutputStream(newFile.getAbsolutePath());
fo.write(strFileContents.getBytes());
fo.close();
}
catch(IOException e)
{Log.v("TEST","Exception on create ");}
Upvotes: 0
Views: 1446
Reputation: 137282
On real device, you can't see these folders if it's not rooted. see this question.
If you want to write files in your app directory, then your code is OK. You can check that it is there in the same way you created it - from your application:
File myFile = new File(getFilesDir() + "/test1.txt");
if (myFile.exists())
{
//Good!
}
Upvotes: 1