请问,如何得到系统的盘符信息 我怎么才能得到系统中有几个盘符,还有每个盘符的具体信息呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 javax.swing.filechooser.FileSystemView 從網上找了一段程序轉給你import java.io.*;public class OpenDirver { private static long getFreeDiskSpace(String dirName) throws Exception { String osName = System.getProperty("os.name"); if (!(osName.equalsIgnoreCase("windows XP") || osName.equalsIgnoreCase("windows 2000"))) return -1; String command = "cmd exe /c dir " + dirName; //操作系统命令 Process process = Runtime.getRuntime().exec(command); //执行操作系统命令。 if (process == null) return -1; BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = ""; String lastLine = ""; while ((line = br.readLine()) != null) { //依次一行行读取,但while循环的目的只是得到最后一行字符。 System.out.println(line); lastLine = line; } lastLine = lastLine.replaceAll(",", ""); //去掉如2,146,623,488中间的逗号。 String[] items = lastLine.split(" "); long freeSpace = -1; for (int i = (items.length - 1); i > 0; i--) { //从最后一个字符串开始遍历。 try { freeSpace = Long.parseLong(items[i]); break; //如果找到目的数据就跳出循环。 } catch (NumberFormatException nfe) { continue; //跳过不是数字的字符。 } } return freeSpace; } public static void main(String[] args) { System.out.println("start-----------------"); try { for (char c = 'A'; c <= 'Z'; c++ ) { String dirName = c + ":\\"; long freeSpace = getFreeDiskSpace(dirName); if (freeSpace != -1) { long number = Math.round(freeSpace / (1024.00 * 1024.00)); System.out.println("<+>>>>" + dirName + " 剩余空间为: " + number + "MB"); } } } catch (Exception e) { e.printStackTrace(); } System.out.println("end-----------------"); }} Calendar.DAY_OF_WEEK的问题? 如何获取面板composite上的子控件 JAVA问题 问一个简单的问题!!! 高分悬赏超级入门问题... 中文教材applet程序显示乱码? 这个问题弄的我好糊涂呀 crash-safe 是什么 帮忙看个简单的问题! 小问题:在线程中调用sleep()使其睡眠的时候,此线程是否释放所占的资源? java位运算 帮我看个java调用oracle存储过程,并且传递数组的例子好吗
import java.io.*;
public class OpenDirver { private static long getFreeDiskSpace(String dirName) throws Exception {
String osName = System.getProperty("os.name");
if (!(osName.equalsIgnoreCase("windows XP") || osName.equalsIgnoreCase("windows 2000")))
return -1;
String command = "cmd exe /c dir " + dirName; //操作系统命令
Process process = Runtime.getRuntime().exec(command); //执行操作系统命令。
if (process == null)
return -1;
BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = "";
String lastLine = "";
while ((line = br.readLine()) != null) { //依次一行行读取,但while循环的目的只是得到最后一行字符。
System.out.println(line);
lastLine = line;
}
lastLine = lastLine.replaceAll(",", ""); //去掉如2,146,623,488中间的逗号。
String[] items = lastLine.split(" ");
long freeSpace = -1;
for (int i = (items.length - 1); i > 0; i--) { //从最后一个字符串开始遍历。
try {
freeSpace = Long.parseLong(items[i]);
break; //如果找到目的数据就跳出循环。
} catch (NumberFormatException nfe) {
continue; //跳过不是数字的字符。
}
}
return freeSpace;
}
public static void main(String[] args) {
System.out.println("start-----------------");
try {
for (char c = 'A'; c <= 'Z'; c++ ) {
String dirName = c + ":\\";
long freeSpace = getFreeDiskSpace(dirName);
if (freeSpace != -1) {
long number = Math.round(freeSpace / (1024.00 * 1024.00));
System.out.println("<+>>>>" + dirName + " 剩余空间为: " + number + "MB");
}
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("end-----------------");
}
}