开发者

What are fields i should change for my codes to suit my own codes?

开发者 https://www.devze.com 2023-03-02 13:00 出处:网络
What are the fields in the example (below) that I should change in relation to my mainActivity.java file? Sorry I\'m kinda new in android/java therefore I don\'t really know what fields to change to s

What are the fields in the example (below) that I should change in relation to my mainActivity.java file? Sorry I'm kinda new in android/java therefore I don't really know what fields to change to suit my existing code. Can someone help?

My mainActivity.java file

File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList");

if(!(dirlist.exists()))
    dirlist.mkdir();

    File TempFile = new File(Environment.getExternalStorageDirectory() + "/VideoList", dateFormat.format(date) + fileFormat);

This is an example I found but I do not know which fields I should change here to suit my code above. I want to preserve its existing function of calculating the size of the directory.

private static long dirSize(File dir) {
    long result = 0;

    Stack<File> dirlist= new Stack<File>();
    dirlist.clear();

    dirlist.push(dir);

    while(!dirlist.isEmpty())
    {
        File dirCurrent = dirlist.pop();

        File[] fileList = dirCurrent.listFiles();
        for (int i = 0; i < fileList.length; i++) {

            if(fileList[i].isDirectory())
                dirlist.push(fil开发者_JAVA技巧eList[i]);
            else
                result += fileList[i].length();
        }
    }

    return result;
}


I don't actually get what do you want, but if you want to get the size of a directory it is:

File dir = new File("c:/dir");

if (!dir.isDirectory()) {
    dir.mkdirs();
}
long dirLength = dir.length();
System.out.println(dirLength);
0

精彩评论

暂无评论...
验证码 换一张
取 消