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
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步