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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM