could you help me about this?.When the users opens the app or install the app the process is to automatically move files in a certain folder. Guys, any suggestion, codes or links are helpful and appreciated ... :D
Thanks in advance.
For move file you can use below code:
File from = new File(Environment.getExternalStorage().getAbsolutePath()+"/folder1/file.ext");
File to = new File(Environment.getExternalStorage().getAbsolutePath()+"/folder2/file.ext");
from.renameTo(to);
just use this method for folders that be on same mount point.
Related
I use some class. That's constructor needs some file path that contains some files.
ex)
Komoran komoran = new Komoran("D:\program_project\lib");
Now I'm making android app. so I can't use absolute path (Because other people who download my app don't have that folder and files)
so I decide to use 'assets' folder that is maybe in APK file. So, final code is like below.
Komoran komoran = new Komoran("file:///android_asset");
but It seems like folder path is wrong(this class doesn't work). What I did wrong ?
This "file:///android_asset" path is used for applications which uses webview ex. cordova/phonegap. As it is part of resources because when Apk is created you can not use this path to access your assets folder. You have to work with context.getResources().getAssets().open("fileName")this code only.
Maybe u can add this code:
context.getResources().getAssets().open("fileName").
u will get a inputstream, and u can do something u want.
No need to use getResources.
You can use directly
context.getAssets().open("fileName").
This is my question.
First I have create my personal folder on create
File parentFolder = new File(MainApplication.getInstance().getExternalCacheDir().getAbsolutePath()
+ File.separator+"myfolder");
if (!parentFolder.exists()) {
parentFolder.mkdirs();
}
Second in my application,i can receive file such as png from another application,and the file that i received has been saved in /Android/data/packageName/cache/myfolder/hashcode/example.png. And i choose the gallery to open it from intent chooser.
When gallery is open and I can see the png file.I kill my application's process and uninstall it.
Finally I install my application again.The path /Android/data/packageName doesn't been created! And create function show that
MainApplication.getInstance().getExternalCacheDir();
returns null!
Give me some advise! Thank you.
Try using
new Context().getApplicationContext().getExternalCacheDir().getAbsolutePath()
I wanna include a text file to my project in smartface appstudio. I put it where? In resources folder or assets? FileStream could not read it in resources (as a drawable item). Any idea?
var txtFile = new SMF.IO.FileStream(SMF.IO.applicationResources, "words.txt", SMF.IO.StreamType.read);
txtFile.readToEnd();
It is not implemented in current release of Smartface App Studio. Also I have tried it before. It is Phase 2 for File Operations.
You can download your static text file from the internet and can save it to the local storage. And read it from there. I can just suggest you this idea. Check some helpful links below.
http://developer.smartface.io/hc/en-us/articles/203177557-File-Operations
http://developer.smartface.io/hc/en-us/articles/202153536-File-Download-Upload
I want a develop simple app in which i have to check at the time of my app installation that directory that i create in my app is already exist before the app is installed, if yes then i have to remove that directory and create new directory in the sdcard.
I am able to do it at installation time but the actual problem is that i put that code in my main activity so when i reopen my app at that time directory is deleted also , so that i don't wont to do because i have put data on that after first installation .
If anyone know the way then please tell me ..
Kind regards,
Jalp.
File dir = new File("/sdcard/dirname/");
if(!(dir.isDirectory() || dir.exists())) dir.mkdirs();
File wallpaperDirectory = new File("/sdcard/dirname/");
// have the object build the directory structure, if
// needed.
if(!wallpaperDirectory.exists())
{ wallpaperDirectory.mkdirs();}
please try this
I have an xml in /data//files/file.xml and another txt file in same location. I am not able to read those files. It throws me error "The application <...> has stopped unexceptedly" with "Force Close" button and the application quits.
Can anyone help me know the cause of it ? I am really stuck up.
You cant access Ur data file like that.
follow these steps
Create a folder in res folder with name as raw . and save your XML file in raw folder.
then use
InputStream inp = Context.getResources().openRawResource(R.raw.datafile);
u will get InputStream reference. where u can proceed further with it as u need.
Thanks Friends,
I found a solution and now could read the file stored in files folder.
Thanks a lot for your help and support.