文章目录
1.删除文件或文件夹(非强制)2.获取文件或文件夹容积
1.删除文件或文件夹(非强制)
synchronized public static boolean deleteFile(String filePath
){
File file
= new File(filePath
);
return file
.delete();
}
2.获取文件或文件夹容积
public static long getFileSize(File file
) throws Exception
{
long size
= 0;
if(file
.isDirectory()){
File
[] fileArray
= file
.listFiles();
for(int i
= 0; i
< fileArray
.length
; i
++){
if(fileArray
[i
].isDirectory()){
size
= size
+ getFileSize(fileArray
[i
]);
}
else{
size
= size
+ fileArray
[i
].length();
}
}
}
else {
size
= size
+ file
.length();
}
return size
;
}
转载请注明原文地址: https://mac.8miu.com/read-500443.html