Skip to Content
author's profile photo Former Member
Former Member

中央管理控制台上传的jar对象程序能否读取配置文件???

中央管理控制台上传的jar对象程序,为计划执行所用,

由于sunny的详细指点,已经成功运行了。见

一个java程序如何在中央管理控制台中加载,使得能使用"计划"这个功能定时运行它?

现在有个问题:

在jar文件的java程序中有

String username="DSSRENHX";

String password = "1";

String cmsName = "dc57";

String authType = "secEnterprise";

现在里面的参数是写进去的,能不能以读取配置文件的方式呢?

方便用户维护

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Aug 12, 2009 at 07:26 AM

    应该是可以的,用Java程序读取配置文件的内容,比如用SAX、DOM、JDOM、DOM4J等读取XML文件中的内容。

    在网上搜了个例子,供你参考:

    XML内容:

    <?xml version="1.0" encoding="GB2312" ?> 
    <Root>
    <Header left="100" Top="30">u65E5u62A5u8868</Header> 
    </Root>

    按照XML里描述的位置 把表头u201C日报表u201D三个字打印出来

    import java.io.File;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.w3c.dom.NodeList;
    
    public class Xml {
     public static void main(String[] args) {
      try {
       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
       DocumentBuilder builder = factory.newDocumentBuilder();
       Document document = builder.parse(new File("E:\\MyWeb.xml"));
       Element rootElement = document.getDocumentElement();
    
       NodeList list = rootElement.getElementsByTagName("Header");
       Element element = (Element) list.item(0);
       System.out.println(element.getChildNodes().item(0).getNodeValue());
    
      } catch (Exception e) {
       System.out.println("exception:" + e.getMessage());
      }
     }
    }

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.