package test; /** * Add one sentence class summary here. * Add class description here. * * @author lxx * @version 1.0, 2004-11-16 */ public class TestCmd { public TestCmd(){} /* public void main(String args[]){ try { Process process = Runtime.getRuntime().exec("cmd.exe /c start http://www.youkuaiyun.com/"); //登录网站 Process process = Runtime.getRuntime().exec("cmd.exe /c start ping 10.144.98.100"); //调用Ping命令 }catch (Exception e) { e.printStackTrace(); } } } */ //在项目下建立一个名为hello的文件夹 public static void main(String[] args) { System.out.println(System.getProperty("user.dir")); createFolder("hello"); } private static void createFolder(String folderName) { String temp = System.getProperty("user.dir") + java.io.File.separator+ folderName; java.io.File f = new java.io.File(temp); f.mkdirs(); } }
利用Java调用可执行命令
最新推荐文章于 2024-05-06 10:28:44 发布
此博客展示了一个Java程序示例。代码包含一个TestCmd类,原main方法中有登录网站和调用Ping命令的尝试,后修改为在项目下创建名为hello的文件夹。通过获取当前项目目录,拼接文件夹路径,使用File类的mkdirs方法完成创建。
340

被折叠的 条评论
为什么被折叠?



