Windows磁盘映射读写远程主机文件

执行CMD命令做磁盘映射:net use X: \\172.17.0.1\D$\test Password /USER:Administrator

Java调用CMD

String cmd = "net use X: \\172.17.0.1\D$\test 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

 

posted @ 2018-04-16 20:59  AaronCnblogs  阅读(2164)  评论(0编辑  收藏  举报