Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>Unfortunately, the proposed answer (getAbsoluteDir) in fact returns a new file using the same path as the file provided.</p> </blockquote> <p>Well, you could skip the <code>lister</code> line, and use <code>mydir.list()</code> instead. However, the code there does not "return" anything -- <code>list()</code> returns the files in a directory, and in that answer, it shows iteration over that list.</p> <blockquote> <p>How do use that string name to list the files that reside in that subdirectory?</p> </blockquote> <p>You can use:</p> <pre><code>File dir=getDir(whateverYourStringNameIs); dir.list(); </code></pre> <p>Or:</p> <pre><code>File dir=new File(getFilesDir(), whateverYourStringNameIs); dir.list(); </code></pre> <p>Basically, get a <code>File</code> object on your directory (which you already know how to get, as you called <code>mkdir()</code> on one), then call <code>list()</code> to get the contents. Once you have the <code>File</code> object, the rest is standard Java I/O.</p> <blockquote> <p>The reason why I'm doing this is I'm passing a reference to this directory (because of the files it contains) through a bundle (across Activities).</p> </blockquote> <p>Assuming that these are all your own activities, you could call <code>getAbsolutePath()</code> on your <code>File</code> to get a <code>String</code> for your <code>Bundle</code>. Then, on the other side, use <code>new File(bundle.getString("whateverYouCalledIt"))</code> to reconstitute the <code>File</code> object. Or, pass in the <code>Bundle</code> a string that represents the relative path within your app's portion of internal storage, and use that with <code>getDir()</code> or <code>getFilesDir()</code> to build a <code>File</code> object pointing to that same path.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload