Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i incorporate these code below into my current existing codes?
    primarykey
    data
    text
    <p>I was task to allocate only 1GB of space to store my videos in a particular file directory where it is going to auto-delete the oldest video file in that directory once its about to reach/hit 1GB? </p> <p>And i eventually found these code but i was left with a problem on how to incorporate these example 1/2 codes into my current existing mainActivity.java file because of the differences in names like "dirlist,tempFile" compared with other examples 1/2 given to perform the task of size checking and deleting. </p> <p>Sorry i'm kinna new in android/java therefore i don't really know what "fields" to change to suit my current coding needs? Can someone help on how am i going to complie these set of codes into a single set of code which perform the above mention functions??</p> <p>My Current existing mainActivity.java</p> <pre><code>File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList"); if(!(dirlist.exists())) dirlist.mkdir(); File TempFile = new File(Environment.getExternalStorageDirectory() + "/VideoList", dateFormat.format(date) + fileFormat); mediaRecorder.setOutputFile(TempFile.getPath()); </code></pre> <p>(Example 1) code for summing up directory file size in a given folder..</p> <pre><code>private static long dirSize(File dir) { long result = 0; Stack&lt;File&gt; dirlist= new Stack&lt;File&gt;(); dirlist.clear(); dirlist.push(dir); while(!dirlist.isEmpty()) { File dirCurrent = dirlist.pop(); File[] fileList = dirCurrent.listFiles(); for (int i = 0; i &lt; fileList.length; i++) { if(fileList[i].isDirectory()) dirlist.push(fileList[i]); else result += fileList[i].length(); } } return result; } </code></pre> <p>(Example 2) set of code for getting all the files in an array, and sorts them depending on their modified/created date. Then the first file in your array is your oldest file and delete it.</p> <pre><code>// no idea what are the parameters i should enter // here for my case in mainActivity?? File directory = new File((**String for absolute path to directory**); File[] files = directory.listFiles(); Arrays.sort(files, new Comparator&lt;File&gt;() { @Override public int compare(File f1, File f2) { return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified()); }}); file[0].delete(); </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.
 

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