我也有兴趣知道是否有一点可以容纳磁盘的大小。
同时这里是我的解决方案 - 用位输出的花哨的文字处理,你可以得到大小 - 它需要华南简介6分钟为70G又可能不是你要找的,但它可能有一半的时间
long tm=System.currentTimeMillis();
try {
String cmd="cmd /c dir c:\\ /s ";
execute(cmd, false);
}
catch (Exception ex) { }
System.out.println((System.currentTimeMillis()-tm));
public String execute(String cmd, boolean getoutput) {
String output=null;
try {
Runtime rt = Runtime.getRuntime();
Process pr=rt.exec(cmd);
StreamGobbler errorGobbler=new StreamGobbler(pr.getErrorStream(), "ERROR", getoutput);
errorGobbler.start();
StreamGobbler inputGobbler=new StreamGobbler(pr.getInputStream(), "INPUT", getoutput);
inputGobbler.start();
int exitVal=pr.waitFor();
System.out.println("ExitValue: " + exitVal);
output=""+errorGobbler.output;
output+=inputGobbler.output;
}
catch(Throwable t) { t.printStackTrace(); }
return output;
}
import java.util.*;
import java.io.*;
public class StreamGobbler extends Thread {
boolean redirect=false;
InputStream is;
OutputStream os;
String type, output="";
StreamGobbler(InputStream is, String type) {
this.is = is;
this.type = type;
}
StreamGobbler(InputStream is, String type, boolean redirect) {
this.is = is;
this.type = type;
this.redirect=redirect;
}
StreamGobbler(OutputStream os, String type) {
this.os = os;
this.type = type;
}
StreamGobbler(OutputStream is, String type, boolean redirect) {
this.os = os;
this.type = type;
this.redirect=redirect;
}
public void run() {
try
{
if(type.equals("OUTPUT")) {
}
else {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line=null;
int i=0;
while ((line = br.readLine()) != null) {
if(redirect) output+=line;
else System.out.println("line "+i+" "+type + ">" + line);
i++;
}
}
} catch (IOException ioe)
{
ioe.printStackTrace();
}
}
}
我希望这会帮助你http://stackoverflow.com/questions/116574/java-get-file-size-efficiently – Rocky