不好意思,再问一下如何用程序获取系统某环境变量的内容,如TOMCAT_HOME sorry,回错了,这个是api不知道java里的方法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 System.setproperty(...)System.getproperty(...) 启动dos窗口,输入set,回车就可以看系统的变量设置了。 呵呵掉调用命令啊可惜不是跨平台的import javax.swing.*;import java.awt.*;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.io.InputStreamReader;import java.io.BufferedReader;public class GetClassPath extends JFrame { JTextPane txt; BufferedReader br; public GetClassPath() throws Exception { super("GetClassPath"); setSize(300, 300); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent ew) { System.exit(0); } }); Container p = getContentPane(); p.setLayout(new BorderLayout()); JPanel p1 = new JPanel(); p1.setLayout(new FlowLayout()); txt = new JTextPane(); JButton getButton = new JButton("Get"); JButton clearButton = new JButton("Clear"); JButton cancelButton = new JButton("Cancel"); ActionListener action = new ActionListener() { public void actionPerformed(ActionEvent ea) { if (ea.getActionCommand().equals("Get")) { try{ getClassPath(); describe(); }catch(Exception e){ } } if (ea.getActionCommand() == "Clear") { try{ clear(); }catch(Exception e){ } } if (ea.getActionCommand() == "Cancel") { try{ describe(); }catch(Exception e){ } System.exit(0); } } }; cancelButton.addActionListener(action); clearButton.addActionListener(action); cancelButton.addActionListener(action); p1.add(getButton); p1.add(clearButton); p1.add(cancelButton); JScrollPane js = new JScrollPane(txt); p.add(js, BorderLayout.CENTER); p.add(p1, BorderLayout.SOUTH); setVisible(true); } public void getClassPath() { try { Process pr = Runtime.getRuntime().exec("cmd.exe /c echo %LASSPATH%"); BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream())); String myvar = br.readLine(); txt.setText(myvar); } catch (Exception e) { txt.setText(e.getLocalizedMessage()); } } public void clear() throws Exception { txt.setText(""); } public void describe() throws Exception{ br.close(); } public static void main(String args[])throws Exception { GetClassPath gp = new GetClassPath(); }} System.setproperty("TOMCAT_HOME")System.getproperty(TOMCAT_HOME) 谢谢楼上的大虾!问题搞定了!:)小生贪心地再多问一句exec方法中参数的写法在哪能够查得到阿?另外不跨平台此话从何说起?是因为exec中调用的方法吗?先谢了谢了。 呵呵那个参数其实就是一些WINDOW下的命令呵呵多看看文档就知道了 因为他只用在WINDOW2000下,如果想用到98或ME下命令还需要改别的平台下也是一样的的呵呵 java调用notepad打开txt相关问题 怎么验证jar的数字签名? 为什么在main()方法里调用一个类里的static方法总是提示"找不到方法"? linux下卸载JDK 大家快来这里呀这里有好多JAVA视频下载 谁有汉字拼音对照表啊?分享一下!谢了! this 请教通过javamail怎样将收件箱中邮件转移到垃圾箱中 java io中有关缓冲区...数据时如何读入到缓冲区的 session 小问题 用JBuilder8新建一Application,取名为:Test1,其它任何都是默认的,点击完成后出错。
System.getproperty(...)
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.InputStreamReader;
import java.io.BufferedReader;public class GetClassPath extends JFrame {
JTextPane txt;
BufferedReader br; public GetClassPath() throws Exception {
super("GetClassPath");
setSize(300, 300); addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ew) {
System.exit(0);
}
});
Container p = getContentPane();
p.setLayout(new BorderLayout());
JPanel p1 = new JPanel();
p1.setLayout(new FlowLayout()); txt = new JTextPane();
JButton getButton = new JButton("Get");
JButton clearButton = new JButton("Clear");
JButton cancelButton = new JButton("Cancel"); ActionListener action = new ActionListener() {
public void actionPerformed(ActionEvent ea) {
if (ea.getActionCommand().equals("Get")) {
try{
getClassPath();
describe();
}catch(Exception e){
} }
if (ea.getActionCommand() == "Clear") {
try{
clear();
}catch(Exception e){
}
}
if (ea.getActionCommand() == "Cancel") {
try{
describe();
}catch(Exception e){
}
System.exit(0);
}
}
};
cancelButton.addActionListener(action);
clearButton.addActionListener(action);
cancelButton.addActionListener(action);
p1.add(getButton);
p1.add(clearButton);
p1.add(cancelButton); JScrollPane js = new JScrollPane(txt);
p.add(js, BorderLayout.CENTER);
p.add(p1, BorderLayout.SOUTH); setVisible(true);
} public void getClassPath() {
try {
Process pr = Runtime.getRuntime().exec("cmd.exe /c echo %LASSPATH%");
BufferedReader br = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String myvar = br.readLine();
txt.setText(myvar);
} catch (Exception e) {
txt.setText(e.getLocalizedMessage());
}
} public void clear() throws Exception {
txt.setText("");
} public void describe() throws Exception{
br.close(); } public static void main(String args[])throws Exception {
GetClassPath gp = new GetClassPath(); }}
System.getproperty(TOMCAT_HOME)
小生贪心地再多问一句exec方法中参数的写法在哪能够查得到阿?
另外不跨平台此话从何说起?是因为exec中调用的方法吗?
先谢了谢了。
呵呵
多看看文档就知道了
因为他只用在WINDOW2000下,如果想用到98或ME下命令还需要改
别的平台下也是一样的的
呵呵