java中有没有读写profile的api.高分 Properties类中有没有写文件的方法。还是得用流来写文件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 以前也是想用Properties文件的,现在觉得还是用JDOM操作xml文件方便点~~~ <?xml version="1.0" encoding="gb2312"?><root><exeRoot dir="d:\rpc\exerun\"><adminuser>系统管理员</adminuser> <adminpass>96E79218965EB72C92A549DD5A330112</adminpass></exeRoot></root>import java.io.*;import java.util.List;import org.jdom.*;import org.jdom.output.*;import org.jdom.input.*;public class Config{ public String exeRoot="",AdminUser="",AdminPass=""; public Config() {} public int readConfig(String inFile) throws Exception { File conF=new File(inFile); try { if (conF.exists()) //if配置文件存在 { SAXBuilder sb = new SAXBuilder(); //建立新构造器 //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 Document doc = sb.build(new FileInputStream(inFile)); Element root = doc.getRootElement(); //得到根元素 List exeRoots = root.getChildren(); //得到根元素所有子元素的集合 Element exeRootOne = (Element)exeRoots.get(0); //得到第一个exeRoot元素 exeRoot=exeRootOne.getAttribute("dir").getValue(); //取得dir属性值 Element adminuserE = exeRootOne.getChild("adminuser"); //取得指定节点adminuser AdminUser=adminuserE.getText(); // 取得指定子节点adminuser的内容 Element adminpassE = exeRootOne.getChild("adminpass"); //取得指定节点adminpass AdminPass=adminpassE.getText(); // 取得指定子节点adminpass的内容 return 1; } else return -4; //配置文件不存在 } catch(Exception e) { System.err.println("Err(-5)!read Config:"+e.getMessage()); return -5; } } public int writeConfig(String outFile,String username,String password) throws Exception { File conF=new File(outFile); try { if (conF.exists()) //if配置文件存在 { SAXBuilder sb = new SAXBuilder(); //建立新构造器 //从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了 Document doc = sb.build(new FileInputStream(outFile)); Element root = doc.getRootElement(); //得到根元素 List exeRoots = root.getChildren(); //得到根元素所有子元素的集合 Element exeRootOne = (Element)exeRoots.get(0); //得到第一个exeRoot元素 Element adminuserE = exeRootOne.getChild("adminuser"); //取得指定节点adminuser adminuserE.setText(username); // 改变指定子节点adminuser的内容 Element adminpassE = exeRootOne.getChild("adminpass"); //取得指定节点adminpass adminpassE.setText(password); // 改变指定子节点adminpass的内容 String indent = ""; // 缩进符号 boolean newLines = false; // 是否产生新行 XMLOutputter outp = new XMLOutputter (indent,newLines,"gb2312"); // 构造新的输出流 outp.output(doc, new FileOutputStream(outFile)); // 输出到XML文件中 return 1; } else return -4; //配置文件不存在 } catch(Exception e) { System.err.println("Err(-5)!write Config:"+e.getMessage()); return -5; } } //验证用户 public boolean CheckUser(String username,String password) { if (!username.equals(AdminUser)||!password.equals(AdminPass)) return false; else return true; }} 怎么判断Query是否为空? java 通信问题 将excel数据导入数据库出现的问题 struts连接池问题 作用域? 被path弄晕了 又是jfreechart乱码~ Java数据库连接池 [向 大家 请教 ] 分不够提问 就90分!!! ! resin 中文乱码问题,急 java起步:执行出错 一个关于EJB很菜的一个问题!!
<root>
<exeRoot dir="d:\rpc\exerun\">
<adminuser>系统管理员</adminuser>
<adminpass>96E79218965EB72C92A549DD5A330112</adminpass>
</exeRoot>
</root>
import java.io.*;
import java.util.List;
import org.jdom.*;
import org.jdom.output.*;
import org.jdom.input.*;public class Config
{ public String exeRoot="",AdminUser="",AdminPass="";
public Config() {}
public int readConfig(String inFile) throws Exception
{ File conF=new File(inFile);
try
{ if (conF.exists()) //if配置文件存在
{ SAXBuilder sb = new SAXBuilder(); //建立新构造器
//从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了
Document doc = sb.build(new FileInputStream(inFile));
Element root = doc.getRootElement(); //得到根元素
List exeRoots = root.getChildren(); //得到根元素所有子元素的集合
Element exeRootOne = (Element)exeRoots.get(0); //得到第一个exeRoot元素
exeRoot=exeRootOne.getAttribute("dir").getValue(); //取得dir属性值
Element adminuserE = exeRootOne.getChild("adminuser"); //取得指定节点adminuser
AdminUser=adminuserE.getText(); // 取得指定子节点adminuser的内容
Element adminpassE = exeRootOne.getChild("adminpass"); //取得指定节点adminpass
AdminPass=adminpassE.getText(); // 取得指定子节点adminpass的内容
return 1;
}
else return -4; //配置文件不存在
}
catch(Exception e) { System.err.println("Err(-5)!read Config:"+e.getMessage()); return -5; }
} public int writeConfig(String outFile,String username,String password) throws Exception
{ File conF=new File(outFile);
try
{ if (conF.exists()) //if配置文件存在
{ SAXBuilder sb = new SAXBuilder(); //建立新构造器
//从文件构造一个Document,因为XML文件中已经指定了编码,所以这里不必了
Document doc = sb.build(new FileInputStream(outFile));
Element root = doc.getRootElement(); //得到根元素
List exeRoots = root.getChildren(); //得到根元素所有子元素的集合
Element exeRootOne = (Element)exeRoots.get(0); //得到第一个exeRoot元素
Element adminuserE = exeRootOne.getChild("adminuser"); //取得指定节点adminuser
adminuserE.setText(username); // 改变指定子节点adminuser的内容
Element adminpassE = exeRootOne.getChild("adminpass"); //取得指定节点adminpass
adminpassE.setText(password); // 改变指定子节点adminpass的内容
String indent = ""; // 缩进符号
boolean newLines = false; // 是否产生新行
XMLOutputter outp = new XMLOutputter (indent,newLines,"gb2312"); // 构造新的输出流
outp.output(doc, new FileOutputStream(outFile)); // 输出到XML文件中
return 1;
}
else return -4; //配置文件不存在
}
catch(Exception e) { System.err.println("Err(-5)!write Config:"+e.getMessage()); return -5; }
}
//验证用户
public boolean CheckUser(String username,String password)
{ if (!username.equals(AdminUser)||!password.equals(AdminPass)) return false;
else return true;
}}