I'm programming an app, which needs to store data in a textfile.
I'm using FileOutputStream:
outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
outputStream.write(data.getBytes());
outputStream.close();
My question is: Where is the file saved?
I can't find it anywhere...
For debugging, I'm using a nexus7.
It's stored under /data/data/<your app> by default. But unless you have rooted device, you have no access to this folder from device. But you can take a look on your file by using DDMS from the Android SDK (at the android-sdk\tools folder)
If You are using Context.MODE_PRIVATE it is stored in application data directory and you do not have access to them from file manager
/data/data/your.app.package.name/files, but note this can be device dependent.. you can find it in eclipse by typing DDMS and then go to file explorer and then follow the above path
writes to a file in your internal directory
/data/data/pacakage/files
Related
I have spent many hours trying to find/create files for an app I am writing. When I pull the application directory name I get: /data/data/com.example.android.[myapp]/files. I am using File(getFilesDir():
File fileDir = new File(getFilesDir() + File.separator);
Log.i(TAG, "File directory: "+fileDir);
When I try to find this path I find many application folders here: Android/data/com but no /data/data folder under Android. There are many other application folders there but not mine. I see the same results whether I use Android Files app or Windows Explorer over USB. I've also tried to look using Eclipse DDMS tab. I see a data folder with a (+) to the left but when I click, it does not expand.
I have also tried creating the directory and file manually with Windows explorer and my app still can't find neither the Android/data/com.example... nor the Android/data/data/com.example... paths.
Also puzzling to me is when the app creates the path and file and write to it (using MODE_WORLD_WRITEABLE) I get no exceptions thrown but then I am unable to read it back or see it with either of the tools mentioned above. I have set the manifest permissions to WRITE_INTERNAL_STORAGE and WRITE_INTERNAL_STORAGE for the app.
Obviously, I am making a very basic mistake.
I am on Android 4.1.2 (API 16).
Sincerely,
ScratchingMyHead
To get the path of my application directory, Try this code sample
PackageManager m = getPackageManager();
String s = getPackageName();
try {
PackageInfo p = m.getPackageInfo(s, 0);
s = p.applicationInfo.dataDir;
} catch (NameNotFoundException e) {
Log.w("yourtag", "Error Package name not found ", e);
}
When I try to find this path I find many application folders here: Android/data/com but no /data/data folder under Android.
That is because you are looking on external storage, not internal storage where your files are. Use DDMS on an emulator to examine internal storage.
I've also tried to look using Eclipse DDMS tab. I see a data folder with a (+) to the left but when I click, it does not expand.
That would sound like what you will get when testing on hardware, as neither you nor DDMS have access to the contents of /data on production hardware.
I have a db located at
ctx.getApplicationContext().getDir("data", 0) + "/" + "db.db4o";
How can I browse this file with an file manager or via USB? I can't seem to find it :<
Browse with file manager, or USB, what does that mean? You can access the data directory, through a file manager, only if you are on a rooted device or an emulator.
Your application specific file are not directly stored in the data directory, but
data/data/your_package_name
you could create an "asset" folder into your android project and put it there. Before that you can try with this:
InputStream is = getAssets().open("db.db4o");
And convert "is" if is necessary.
Regards
My app creates sqlite database which file path starts with "/data/data/". From what I can see, data is stored correctly. But when I try to find the file itself (with ES Explorer), I just can't! Even the path "/data/data/" doesn't exist. Where can it be?
You can find your database in
/data/data/your.application.package/databases/your_db_name
This is the default path to your database
You don't have permission to look at that folder in your file explorer. In an emulator the same happens in the Eclipse file explorer. You can however access this path in the debug mode.
It really is in /data/data/your.application.package/databases/dbname.db
/data/data/[your_package_name]/databases/[your_db_name].db
An Air app which loading data from an external XML file (cfg.xml). I've published the Android/Air file, included the cfg.xml file in the Android package. Then I've installed on my SD Card(). App's reading xml file - working perfectly. But I need raw access(on my device) to cfg.xml I cannot find this file, checked everywhere(Rooted Phone). Where is it? Is there other solution? I need a file which is easy to read/write.
Use DDMS -> File Explorer and look for you app name in folders like data, ...
Solution:
Use fileStream instead of URLLoader
Change directory to SD Card e.g.
File.userDirectory.resolvePath("YourAppData/cfg.xml")
(No rooted phone needed)
My program opens a .txt file from the assets folder and reads from it. Here is the code:
AssetManager myAssetManager = myContext.getAssets();
try{
InputStream is = myAssetManager.open("databaseeleven.txt");
byte[] bytes = new byte[is.available()];
is.read(bytes);
commands = new String(bytes);
} catch(IOException e){
Toast.makeText(myContext, e.getMessage(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}//try-catch
I have noticed that when I make changes to the file called databaseeleven.txt and save the file, my changes aren't reflected on the emulator when I run my program again. The project is saved to a thumb drive. I checked it to make sure there's only one file with that name, and it is up to date. I know the application is re-downloaded because of changes to the code. I'm using egit, Eclipse version 3.6.2, and ADT version 10.0.1. Does anybody know why my program isn't working off this saved file?
Update: Refreshing and then cleaning the project again doesn't help.
If i have understood your problem correctly, you are trying to alter the file in /assets folder. changing .apk contents after signing the package is not possible.
If the file is small, copy it into your app's private data directory.
If the file is bigger, copy it into the /sdcard.
It was happening to me with a .sqlite file in the assets folder and I solved it by
uninstalling the app from the phone
and rebuilding.
What's the file size of databaseeleven.txt?
There is a limit of 1MB per file for the assets file, if the file size exceeds this limit it won't be available in your apk.
If this is your case, there are two alternatives I know of:
Split your file into 1MB chunks, you have an example this in this SO question
Use a file extension that doesn't get compressed by Android, as suggested here. Note that your file won't be compressed and you will probably end up with a big apk.
NOTE: It seems that the 1MB limit was removed in Android 2.3, so this only applies to 2.2 and lower.
Clean the project after you edit the file....hope this helps
hi try after refreshing the project in eclipse and clean & build it again. Hope you will be able to find the changes reflected in the emulator
If its a txt file of your format, you should be doing something like this
InputStream ins = getResources().openRawResource(R.raw.options);
where "options" is options.txt file in the ~/res/raw folder.
Any changes to this file will still require a publish/deploy back to the device/emulator so it has the latest apk.
Hope this helps...