你的命令行不对?
我的机器上可以执行
import java.io.*;public class errout {
public static void main(String[] args) {
Process listmgr;
DataInputStream addResult;
int BUFFER_SIZE = 1000;
int byteCount = -1; String s = new String("cmd dir");
// for (int i = 0; i < args.length; i++)
// s = s + " " + args[i];
try{
listmgr = Runtime.getRuntime().exec(s);
addResult = new DataInputStream(
new BufferedInputStream(listmgr.getInputStream()));
byte[] resultBuf = new byte[BUFFER_SIZE];
byteCount = addResult.read(resultBuf);
if (byteCount != -1) {
String result = new String(resultBuf).trim();
System.out.print(result);
}
else
System.out.println("No Data");
}
catch(IOException e){e.printStackTrace();}
}
}
我的机器上可以执行
import java.io.*;public class errout {
public static void main(String[] args) {
Process listmgr;
DataInputStream addResult;
int BUFFER_SIZE = 1000;
int byteCount = -1; String s = new String("cmd dir");
// for (int i = 0; i < args.length; i++)
// s = s + " " + args[i];
try{
listmgr = Runtime.getRuntime().exec(s);
addResult = new DataInputStream(
new BufferedInputStream(listmgr.getInputStream()));
byte[] resultBuf = new byte[BUFFER_SIZE];
byteCount = addResult.read(resultBuf);
if (byteCount != -1) {
String result = new String(resultBuf).trim();
System.out.print(result);
}
else
System.out.println("No Data");
}
catch(IOException e){e.printStackTrace();}
}
}
解决方案 »
- android系统,如何画信号强度界面(如图)
- 如何利用java的多线程对单个文件进行读取
- 急需答案!!!
- 如何获取本机的子网掩码?急救!!
- junit4有没有可以记录@Test方法中每条语句执行时间的功能
- java制图问题求教
- 不知道sun这样的公司用什么开发工具,Sun One Studio,JBuilder还是Editor+Ant?
- 如何从C++更快地转到Java编程呢?
- 求返回值进来看看,给点意见:有一组物料,每一个物料对应一组出仓和入仓情况,每一个出仓对应一组值!在线等待中......................
- ☆ 请教大虾,如何在jar文件中设置 main-class ☆
- ABC 经常看到Java TM 字样﹐请问下TM表示什幺意思?
- 这是什莫错误?急,如何解救
可是你的答案执行后并没有显示dir的结果啊。是不是cmd dir后要带什么参数呢?