设为首页 加入收藏

TOP

利用Java设置UNIX/Linux环境变量
2014-11-24 02:04:23 来源: 作者: 【 】 浏览:1
Tags:利用 Java 设置 UNIX/Linux 环境 变量

public class SetEnv {
/**
* judst MANAGERTOMAT_env has in env
*
* @return string
*/
public static String getTomcatEnv() {
String env = null;
Map map = System.getenv();
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
if (entry.getKey().equals("MANAGERTOMCAT"))
env = entry.getValue().toString();


}
return env;
}


/**
* 写文件
*
* @param path
* @param filename
* @return
*/
public static boolean writeFile(String path) {


File file = new File("/etc/profile");
FileWriter fw;
try {
fw = new FileWriter(file,true);
fw.write("export MANAGERTOMCAT=" + path);//环境变量名
fw.write(System.getProperty("line.separator"));
fw.close();
} catch (IOException e) {
return false;
}
return true;
}


/**
* test
*
* @param args
*/
public static void main(String[] args) {
if(args.length!=0)
{
writeFile(args[0]);//传参
}
}
}
#~~~~~~~~~~~~~~~~~~


终端输入:


javac SetEnv.java


java SetEnv /root/test


后重启计算机


即可


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇UltraEdit中Java编译运行设置方法 下一篇Linux下程序编写笔记

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: