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.
Related
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
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.
I've researched this problem for a while now and I've only found really complicated answers so I'm very confused. Keep in mind that I'm not an expert programmer so don't expect me to know a ton about this!
All I want to do is print a new line of characters to a text file located in the downloads folder of an SD card in Android. I set up my emulator to have an SD card and placed the text file in the downloads folder. This piece of code is for a database class that will access a text file in an SD card to read the data. I know that the class works outside of Android so assume that all of the methods are working as they should to read the data!
I get an IOException when I run this method in another class:
public void addRecordToDataBase(ChildRecord c) throws IOException
{
FileWriter outFile = new FileWriter("/mnt/sdcard/download/database.txt");
PrintWriter out = new PrintWriter(outFile);
out.println(c.printToDataBase());
out.close();
}
The weird thing is I can read from the database just fine in other methods using that same path; no problems there. I just can't write to it. I've read somewhere that you can use "regular Java methods" to write to an SD card in Android without those crazy "OutputStream" things all over the place. Is this true? I debugged this thing and found out that the line of code that is throwing the exception is right here:
FileWriter outFile = new FileWriter("/mnt/sdcard/download/database.txt");
If anyone has any idea why I'm geting this IOException, I would be really grateful! I did try all the crazy methods that Android wants to use but I think I got lost in it so I just reverted back to what I knew how to do.
Thank you so much!
My guess is you can't access such directory with writing permissions, at least in that manner.
Did you take a look at http://developer.android.com/guide/topics/data/data-storage.html#filesExternal?
That reference and this one (http://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)), explaining how getExternalFilesDir works, may be of help to you!
Have you declared the WRITE_EXTERNAL_PERMISSION permission in your apps manifest file?
In my application I need to store the images in assets folder and should display them. I have tried all ways but still the image is not displaying. I have tried using Asset Manager, InputStream and Uri but no result finally. Please help me with this issue. I am struugling a lot ...Can u please tell how to give the path....for example I saved my images in assets folder then I am giving as
InputStream val=getAssets().open("/assets/62.gif");
Is that path correct? Please tell me where I went wrong..
Thanks in Advance
Asset file is accessible through following URI:
file:///android_asset/62.gif
Just open it and use
Use
InputStream val=getAssets().open("62.gif");
I have few html files in assets folder of my application. My application loads these files depending on the device language. When I check for the existance of the file it say does not exist, but when I load that file using browser.loadUrl(filename), it loads it fine.
Following code will help you to understand my problem:
String filename="file:///android_asset/actualfilemname.html";
File f = new File(filename);
if(!f.exist){
filename = "file:///android_asset/newfile.html";[Everytime it loads this file even though I have actualfilename.html in the folder]
}
browser.loadUrl(filename);
[it loads the newfile.html but not actualfilename.html]
You can't use File for resources. You'll need to use the AssetManager for that.
(In the off-chance that File does handle resources, which I don't think it does, you'll have to convert the path to a URI first, for example using URI.create(). File(String) expects a path, not a URI.)
Is this the exact code you are using? you probably want to be calling f.exists() not filename.exist().
Edit: try working with the AssetManager instead of hard coding your file path. My best guess is that the file path you are using is not exactly how it supposed to be.