How To Read From The Internal Storage (subfolder Download)?
After intensive search I could not find out how to read a configuration file (xml) from the internal storage (sub-folder download). I tried to access /mnt/sdcard/Download/config.xm
Solution 1:
Set the Read-Permission in your AndroidManifest.xml:
<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE"/>
Use the following code:
Stringfilename= Environment.getExternalStorageDirectory().getPath() + File.separator + "download" + File.separator + "config.xml";
- Use
filename
for whatever you want to do.
Solution 2:
You may try following code when you face a condition to read a file from a subfolder in internal storage. Sometimes you may get problems with openFileInput whey you trying to passing context. here is the function.
publicStringgetDataFromFile(File file){
StringBuilder data= newStringBuilder();
try {
BufferedReader br = newBufferedReader(newFileReader(file));
String singleLine;
while ((singleLine= br.readLine()) != null) {
data.append(singleLine);
data.append('\n');
}
br.close();
return data.toString();
}
catch (IOException e) {
return""+e;
}
}
Post a Comment for "How To Read From The Internal Storage (subfolder Download)?"