package cn.com.sh.diskspace;import java.io.BufferedReader;
import java.io.InputStreamReader;public class Diskspace {
private Diskspace() {
} public static long getFreeDiskSpace(String dirName) {
try {
String os = System.getProperty("os.name");
String command;
if (os.equals("Windows NT") || os.equals("windows 2000")) {
command = "cmd.exe /c dir " + dirName;
} else {
command = "command.com /c dir " + dirName;
}
Runtime runtime = Runtime.getRuntime();
Process process = null;
process = runtime.exec(command);
if (process == null) {
return -1;
}
BufferedReader in = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line;
String freeSpace = null;
while ((line = in.readLine()) != null) {
freeSpace = line;
}
if (freeSpace == null) {
return -1;
}
process.destroy();
freeSpace = freeSpace.trim();
freeSpace = freeSpace.replaceAll("\\.", "");
freeSpace = freeSpace.replaceAll(",", "");
String[] items = freeSpace.split(" ");
int index = 1;
while (index < items.length) {
try {
long bytes = Long.parseLong(items[index++]);
return bytes;
} catch (NumberFormatException nfe) {
}
}
return -1;
} catch (Exception exception) {
return -1;
}
} public static void main(String[] args) {
if (args.length == 0) {
for (char c = 'A'; c <= 'Z'; c++) {
String dirName = c + ":\\";
System.out.println(dirName + " " + getFreeDiskSpace(dirName));
}
} else {
for (int i = 0; i < args.length; i++) {
System.out.println(args[i] + " " + getFreeDiskSpace(args[i]));
}
}
}
}(1)程序见上,怎么打印结果都是-1,改是,BufferedReader对象没有读到流中的数据吧,怎么解决?
(2)谁能告诉我一个有用的Jconfig的下载地址
(3)先在这里感谢各位的帮忙

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【liuxinghua60】截止到2008-07-08 16:18:21的历史汇总数据(不包括此帖):
    发帖的总数量:3                        发帖的总分数:120                      每贴平均分数:40                       
    回帖的总数量:0                        得分贴总数量:0                        回帖的得分率:0%                       
    结贴的总数量:0                        结贴的总分数:0                        
    无满意结贴数:0                        无满意结贴分:0                        
    未结的帖子数:3                        未结的总分数:120                      
    结贴的百分比:0.00  %               结分的百分比:0.00  %                  
    无满意结贴率:---------------------无满意结分率:---------------------
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    问题应该出现在这里
    command = "command.com /c dir " + dirName;好像要用String[] 来做
    具体等我明天查一下以前写的代码 里有
      

  3.   

    String[] cmd = {"sh", "-c",""};
    /**
     *
     */
    public String getHardView(String exe) throws IOException {
    cmd[2] = exe;
    LineNumberReader in = new LineNumberReader(new InputStreamReader(
    Runtime.getRuntime().exec(cmd).getInputStream()));
    String line = null;
    StringBuffer temp = new StringBuffer();
    while ((line = in.readLine()) != null) {
    temp.append(line);
    }
    return temp.toString();
    }命令行
    hda=df /dev/mapper/VolGroup_ID_11915-LogVol2 
      

  4.   

    楼上传过来的参数时总样的,命令行hda=df /dev/mapper/VolGroup_ID_11915-LogVol2起什么作用