我需要运行包含cd命令的批处理(.bat)文件,以进入目录并使用Java来获取文件,但它没有执行CD命令。
import java.io.IOException;
import java.io.InputStream;
public class BatchRun {
public static void main(String[] args) {
// TODO Auto-generated method stub
Runtime runtime = Runtime.getRuntime();
try {
Process p1 = runtime.exec("cmd /c start C:\\Users\\543543\\Desktop\\Test.bat");
InputStream is = p1.getInputStream();
int i = 0;
while( (i = is.read() ) != -1) {
System.out.print((char)i);
}
} catch(IOException ioException) {
System.out.println(ioException.getMessage() );
}
}
}