我应该更改代码的哪些字段以适合我自己的代码?
我应该更改与 mainActivity.java 文件相关的示例(如下)中的哪些字段?抱歉,我对 android/java 有点陌生,因此我真的不知道要更改哪些字段以适合我现有的代码。有人可以帮忙吗?
我的 mainActivity.java 文件
File dirlist = new File(Environment.getExternalStorageDirectory() + "/VideoList");
if(!(dirlist.exists()))
dirlist.mkdir();
File TempFile = new File(Environment.getExternalStorageDirectory() + "/VideoList", dateFormat.format(date) + fileFormat);
这是我找到的一个示例,但我不知道应该在此处更改哪些字段以适合上面的代码。我想保留其现有的计算目录大小的功能。
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(fileList[i]);
else
result += fileList[i].length();
}
}
return result;
}
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(fileList[i]);
else
result += fileList[i].length();
}
}
return result;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我实际上不明白你想要什么,但是如果你想获取目录的大小,它是:
I don't actually get what do you want, but if you want to get the size of a directory it is: