java检测磁盘

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

packagecom.fz;importjava.io.File;publicclassFIletest{privatestaticfinalFile[]rootDirArray=File.listRoots();/***@paramargs*/publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubfor(Filedir:rootDirArray){System.out.println(dir.getPath());longusableSpace=dir.getUsableSpace();System.out.println(Usablespace=+usableSpace);System.out.println(usableSpace/1024.0/1024.0/1024.0+G);longtotalSpace=dir.getTotalSpace();System.out.println(Totalspace=+totalSpace);System.out.println(totalSpace/1024.0/1024.0/1024.0+G);}}}packagecom.fz;importjava.io.File;importjava.text.DecimalFormat;importjava.text.NumberFormat;publicclassGetFolderSize{inttotalFolder=0;inttotalFile=0;publicstaticvoidmain(Stringargs[]){Stringfolder=d:;try{GetFolderSizesize=newGetFolderSize();longfileSizeByte=size.getFileSize(newFile(folder));System.out.println(FolderSize:+fileSizeByte+Bytes);//System.out.println(TotalNumberofFolders:+size.getTotalFolder());//System.out.println(TotalNumberofFiles:+size.getTotalFile());}catch(Exceptione){}}publiclonggetFileSize(Filefolder){totalFolder++;//System.out.println(Folder:+folder.getName());longfoldersize=0;File[]filelist=folder.listFiles();for(inti=0;ifilelist.length;i++){if(filelist[i].isDirectory()){foldersize+=getFileSize(filelist[i]);}else{totalFile++;foldersize+=filelist[i].length();}}returnfoldersize;}publicintgetTotalFolder(){returntotalFolder;}publicintgetTotalFile(){returntotalFile;}}

1 / 3
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功