I made an app that i'm am working on updates for and in the old version I hard coded the file path like this
"/data/data/my.app.here/troll"
so now I am trying to do an update and I am trying to use something similar to
Context.getFilesDir()
but that returns
/data/user/0/my.app.here/files
the app info is stored on the troll file and when I push updates I don't want to use another path and have them start their information all over again. What's the best way to resolve this situation?
Can someone kindly tell me the best way to resolve this situation?
Call getParentFile() on the File returned by getFilesDir() to get its parent directory. Your troll file should be in there. That wasn't a great place to put a file, and so YMMV.
If your concern is the /data/user/0/, that will be handled by Android and should map to /data/data/ when the primary user is the one running your app.
Related
I'm in doubt about something. I'm developing a Java Desktop application and I have a problem.
I need to get the current local folder that my application (jar file) is in user system. And after this, to search inside of this same folder for some files (like all .txt file, for example). And finally, get the name of only one of this files and converts to string.
Someone can help me?
Antecipate thanks.
May be the getCanonicalPath() and getProperty() functions could help you, since you don't show any code I can't make you any example, but may be looking this could help you a little.
And also there is a similar question here
I'm working on an embedded android project and I'm facing a weird problem.
I'm saving values on xml config files (using the transform class). I'm sure that the save operation finished (but I have to handle the save not finished case later).
if I shutdown the board in the screen where the files are saved. After the next startup, the config files are empty!!!!
I tried FileWriter and FileOutputStream instead of the transform class (I, of course, closed the stream after use) but I'm facing the same problem.
I tried to use a backup file to avoid this issue: I write into a new file, then delete the original one and renamed the new one with the original name. this solution doesn't fix the problem!!
I tried another solution: I created a backup file. I saved into this one, and then I copied this one into the original one (without any deleting). after my test case, the two files are empty!!!!
I's really a weird problem!! does anyone faced the same issue on android or on another os? I saw that question too content of XML file created by java app dissapears if computer is shut down and I think it's a the same issue.
Is this a java issue? any solutions?
Thank you for your help
Regards
I didn't find the root cause. I think it's mostly related to the board than android. I find a turn around, I created the backup files into the private storage space /data/data/my.package.name (which is located in the Nand flash in my case) and when my application started, if the config file is empty, I use the backup file from the private storage.
Really a weird problem but my issue is solved.
Cheers
I want to create my own file format for a particular kind of file. When someone downloads this file I want their system to know it should be opened with my application.
For example when I download a .doc file, my computer asks me whether I want to save the file or open it with Open Office. Similarly, If that .doc file is sitting on my desktop, and I double click it, it automatically opens with the correct application.
I believe this has to do with associating the file extension with the application in the context of the underlying OS.
Can any one point me to some good resources about how to do this in java?
Thanks.
Edit:
Sorry I want to clarify. Is there a way I can have my application associate the file type with itself when it is installed?
Edit:
found this...
http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/
platform independent solution
This source shows how to make a file association in windows:
http://www.rgagnon.com/javadetails/java-0592.html
You will probably have to do it per installer that you make in each OS.
found this... http://java.sun.com/developer/technicalArticles/J2SE/Desktop/jdic_assoc/ platform independent solution
My Android application downloads data only the first lunch. the data is ~50 mb with ~2500 files.
1. Is it a good idea to store if the files got downloaded in SharedSettings? The problem is that if a user clears the data application (maybe by mistake), he has to redownload everything. I manually copy a prepacked database to /data/data/../databases/, is it a good idea to check if the db exists, and if no then download everything?:
if(new File(/data/data/../databases/myDB.db).exists){//dont download}
2.Is getting the folder size and checking if its the same a good way to see if the folder+data are good? or is there a better way to check if 2 folders are the same?
Thanks.
No, do not put 50MB of data into SharedSettings. That will fall over and die. A set of SharedSettings is stored in XML on disk and entirely loaded into RAM when opened. This also won't keep the user from clearing this data.
For determining whether the data has been downloaded, I would suggest just having a file you make once the download is complete indicating it is done. The user can't selectively remove files. They can clear your data, but that will also clear the sentinel file and you will know you need to re-download. (Also keep in mind you will need to deal with restarting the download if it gets interrupting in the middle.)
Also be sure you correctly handle filesystem operations as described here: http://android-developers.blogspot.com/2010/12/saving-data-safely.html
An alternate idea if you're worried about missing data files... If at any point your app looks for a file and it doesn't exist, throw an exception, pass it to a handler that shows a dialog and 'verifies' your data. You can keep a list of all needed data files, and then only download ones that don't exist. Something like a system check, if you will.
That way they don't end up downloading 50MB if they were only missing a couple files they accidentally deleted in root explorer ;-)
I am using Java to develop an application, it needs to manage the file on the computer. The application have the ability/function to delete the file on the system. But I want to check whether the selected file is using/reading by another application or not first. Because I don't want to delete the file which is reading/using. How can I do so?
Maybe you could use tryLock()?
On Windows, you can't delete files which are in use ("locked"). Java itself doesn't offer an API to check.
If another application is using the file or actively reading it, then provided that application has done its job correctly (opening the file with a read lock), you won't be able to delete the file -- you'll get an IOException (specifically, a sharing violation). Catch the exception to know whether there was a problem.