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