java - FileUtils.readFileToString IOException -


i'm new android app development. currently, i'm trying android download folder path , log it. this, use commons io library. i've got code:

    file folder = environment.getexternalstoragepublicdirectory(environment.directory_downloads);     log.e("files", folder.listfiles().length + " items"); try {     string dfolder = fileutils.readfiletostring(folder);     log.i(tag2, dfolder); }catch (ioexception e){     toast.maketext(getapplicationcontext(), r.string.fail,             toast.length_short).show(); } 

for reason i'm getting ioexception every time, i'm receiving amount of files in folder 2nd line.

i've got permissions in manifest

<uses-permission android:name="android.permission.read_external_storage" /> <uses-permission android:name="android.permission.write_external_storage" /> 

fileutils.readfiletostring reads contents of file string. environment.getexternalstoragepublicdirectory(environment.directory_downloads) return directory, not file, using readfiletostring on throw ioexception. if want read contents of files in download directory, that.

 file folder = environment.getexternalstoragepublicdirectory(environmeng t.directory_downloads);  for(file file:folder.listfiles()){   try {     string dfolder = fileutils.readfiletostring(file);     log.i("file contents ", dfolder);   } catch (ioexception e) {     toast.maketext(getapplicationcontext(), "failed!", toast.length_short).show();   } } 

if there many files in directory, throw outofmemoryerror.

edit: if need path of foler use

 file folder = environment.getexternalstoragepublicdirectory(environment.directory_downloads);  log.i("folder path",folder.getabsolutepath()); 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -