Where can I see the file in path getApplicationContext().getFilesDir() - android

I am using the below code to create a file in android as
File file = new File(getApplicationContext().getFilesDir(), "content.txt");
I want to open the file in my phone. I went to the path
Local storage/Android/data/<my package>/files/
However, I cannot see the file. My Android version is 5.0.1. What is happen? One more thing, Do you think the above way is a good way to save file? What is common path to save a file in Android? Thanks

The file locates in /data/data/[your package]/files,it's app private directory.
It's a good way or not depends on the purpose of your file.
if you want your file visable only to you(the app developer),the folder is right
if the file can be visable to others and the file is large,then you can put it to sdcard folder
if you want the file stay even if your app being removed,you shouldn't put it in this folder.Because when an app removed,the all data in /data/data/[package name]/ will be deleted also.

You find in:
/data/data/[your package name]/files/

Related

Add file in apk so that user can access it?

I want to add my one file (example mp3) inside an apk so that when user start that application for the first time it should copy that file into phone memory.
Can someone give me some suggestions regarding how to do this?
Try putting the mp3 file in the assets/ folder. if your project doesn`t have one, create one on the same level as your res/ folder. Then, when the app runs, save the file to the sd card.
Have try to put your file into raw or asset folders.because when AAPT packaging for .apk with .class then its focuse goes to res folders and then at last to manifest file...so when you puts your file into these folders then these files takes their space into .apk.
And use a variable to know your Application is installed for very first time then make folders(where you want) to copy that file...

Android load and modify file

I have a short question about writing to a file in android. I am writing a game where I use a xml file to save some data about the level stats. Now I have seen that if I save this xml file in AssetManager it is not possible to change it (only permissions to read files).
Now because I can only modify files which are in the filesystem of android (using openFileInput and openFileOutput to work with it) I wonder where I have to save my (already existing) xml file in my eclipse project so that I can use openFileInput to load it and change it via code.
Do I have to make a new folder? E.g. project_path/files/myxml.xml.
Is it even possible to load a file which was created (outside the AssetManager folder) before installing the .apk to target?
If it is possible does anybody have some example code?
I hope you understand my question.
There is no such place. Installation of android apps does not include an automatic step that would copy your content from apk to the internal folder (and your application does not reside in the folder either).
You will have to create your XML file in code, possibly checking for its existence before each access (or using some other marker).

Keeping a text file in android

I am new to android and facing issue with file system usages.
I have seen several threads but i am still not able to find the answer which i am looking for my requirement.
I have a original file say test.xml which i want to keep somewhere in my eclipse project so that as soon as i install the app it should move my test.xml file into data directory so that i would be able to read it
please refere this link :
http://developer.android.com/training/basics/data-storage/files.html
I want to save my original file at : "/data/data/com.example.helloWorld/files"
I should be able to get the file handle form the below command
File file = new File(context.getFilesDir(), filename);
Please Note i dont want to save my file in asset folder.
Thanks,
Manish Bansal
I recommend you use assets as storage for your file initially as that will get compiled with your app, then once the user starts your app you check if your file exists and if not you can save the asset to the internal storage location as specified in the documentation, from there you can use the file as you like in the filesystem.

Load External Text File Into Android App Without Using Resources

I have an android application I am developing in Java.
I need it to load a text file so it can read what is in the text file and get values from it.
However, everything I have read so far has been directing me to use resources and package it up with the application.
However this means if I want to change the text file, I have to reinstall the application, which is not what I want.
I need to end up with the .apk file and the .txt file in the same folder on my android phone so I can change the .txt file and the app reads in the text file in its directory.
Can anyone help?
No, you do not want to end up with the .apk and the .txt file in the same folder.
You want to end up with the .txt in some place that's always the same and that you know about.
You can deploy the initial .txt via the ressources (aka: package it and copy it to the sd for example) and later download a new version (or copy something to the device via usb).
Then inside your app check if the file exists and open it with standard Java. There's plenty of source around for that.

Android - update a file in res/raw folder

I want to update the content of a file on my res/raw folder called dbschema.xml, using a newer version of dbschema.xml that is somewhere on the phone (for exemple, at data/data//dbschema.xml)
I've already done the part to check if the new file exists, and i want now to copy it to raw.
Do you have any idea?
Thanks.
It's not possible, you can't modify the content of those files since they are inside the installation package. You could instead copy the file to the private directory of your app, read it from there and update when needed.

Categories

Resources