Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In your question, you are pointing a Directory, not a File.</p> <pre><code>File file = new File(Environment.getExternalStorageDirectory() + dir); private final Activity context; Date lastModified = new Date(file.lastModified()); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); String formattedDateString = formatter.format(lastModified); </code></pre> <p>The idea is to get a Directory and iterate searching for the Last modified date of all files. The following question may help: <a href="https://stackoverflow.com/questions/5005965/how-to-get-only-10-last-modified-files-from-directory-using-java?rq=1">How to get only 10 last modified files from directory using Java?</a></p> <p><strong>EDIT 1:</strong></p> <p>My Tricky Solution: </p> <pre><code>File images = new File("YourDirectoryPath"); long[] fileModifieDate = new long[images.listFiles().length]; int i=0; File[] imagelist = images.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { File file = new File(dir, name); fileModifieDate[i++] = file.lastModified(); return true; } }); // Here, max is the last modified date for this directory // Here, Long array **fileModifieDate** will give modified time of all files, which you can also access from Files array // if you want the last modified file in the directory you can do this: File[] maxModifiedDate = images.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { File file = new File(dir, name); return file.lastModified() == max; } }); // Now **maxModifiedDate** File array will have only one File, which will have max modified date. </code></pre> <p><strong>EDIT 2:</strong></p> <p>For your case, this would be helpful:</p> <pre><code>public class MyAdapter extends ArrayAdapter&lt;String&gt; { String dir = "/FileDirectory/"; File myFolder= new File(Environment.getExternalStorageDirectory() + dir); if(myFolder.exists()){ File[] filelist = myFolder.listFiles(new FilenameFilter() { public boolean accept(File dir, String name) { return true; } }); } </code></pre> <p>// Now you have a <strong>filelist</strong> array of Files. If you want lastModified data, you can fetch from each individual file as you were doing previously:</p> <pre><code> private final Activity context; Date lastModified = new Date(file.lastModified()); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); String formattedDateString = formatter.format(lastModified); private String dateFormat = "dd/MM/yyyy HH:mm:ss"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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