下面的程序我刚通过,希望对你有所帮助,仅能获取当前驱动器信息(如你将java程序放入c:\就可以获取c:\信息),加入了判断操作系统代码:
package test;import java.io.*;public class DiskInfo {
public DiskInfo() {
} public static void main(String[] args) {
DiskInfo diskinfo= new DiskInfo();
String osname = System.getProperty("os.name"); String command = ""; if (osname.indexOf("NT") > -1) command = "c:\\winnt\\System32\\cmd.exe"; else if (osname.indexOf("Windows") > -1) command = "c:\\windows\\System32\\cmd.exe"; try {Process p = Runtime.getRuntime().exec( command + " /c dir > c:\\diskinfo.txt"); p.waitFor(); }
catch (Exception ex) {
System.out.print(ex.getMessage());
}
try{File f=new File("c:\\diskinfo.txt");
FileInputStream fis=new FileInputStream(f);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException ex) {
System.out.print(ex.getMessage());
}
catch (IOException ex) {
System.out.print(ex.getMessage());
}
}
}
package test;import java.io.*;public class DiskInfo {
public DiskInfo() {
} public static void main(String[] args) {
DiskInfo diskinfo= new DiskInfo();
String osname = System.getProperty("os.name"); String command = ""; if (osname.indexOf("NT") > -1) command = "c:\\winnt\\System32\\cmd.exe"; else if (osname.indexOf("Windows") > -1) command = "c:\\windows\\System32\\cmd.exe"; try {Process p = Runtime.getRuntime().exec( command + " /c dir > c:\\diskinfo.txt"); p.waitFor(); }
catch (Exception ex) {
System.out.print(ex.getMessage());
}
try{File f=new File("c:\\diskinfo.txt");
FileInputStream fis=new FileInputStream(f);
BufferedReader br=new BufferedReader(new InputStreamReader(fis));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (FileNotFoundException ex) {
System.out.print(ex.getMessage());
}
catch (IOException ex) {
System.out.print(ex.getMessage());
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货