执行CMD命令做磁盘映射:net use X: \172.17.0.1D$ est Password /USER:Administrator
Java调用CMD
String cmd = "net use X: \172.17.0.1D$ est Password /USER:Administrator";
Process process = Runtime.getRuntime().exec(cmd, null); InputStreamReader in = null; BufferedReader lin = null; try { in = new InputStreamReader(process.getErrorStream()); lin = new BufferedReader(in); String str; while ((str = lin.readLine()) != null) { LOG.info(str); } try { process.waitFor(); //等待进程执行完毕 } catch (InterruptedException e) { LOG.info("", e); } } catch (Exception e) { LOG.error("", e); } finally { if (null != in) { try { in.close(); } catch (Exception e) { LOG.info("close faild"); } } if (null != lin) { try { lin.close(); } catch (Exception e) { LOG.info("close faild"); } } } LOG.info(process.exitValue());
删除磁盘映射:net use X: /delete