易截截图软件、单文件、免安装、纯绿色、仅160KB

java 操作XML文件(片段)

//create a new Document
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document d = db.newDocument();

//add root Node
Element noteuser = d.createElement("note-users");
d.appendChild(noteuser);

//add exists Node
Document readXML = db.parse(new File("c:\\note-user.xml"));
NodeList nl = readXML.getElementsByTagName("user");
for(int i = 0; i < nl.getLength(); i++)
{
Element n = d.createElement("user");
n.setAttribute("name", nl.item(i).getAttributes().getNamedItem("name").getNodeValue());
if(id !=null && id.equals(nl.item(i).getAttributes().getNamedItem("name").getNodeValue()))
{
//duplicate id (redirect to error page)
response.getWriter().print("<font color = red>duplicate id !</font>");
response.getWriter().print("      ");
response.getWriter().print("<a href = \"reg.jsp\">return to login page</a>");
return;
}
n.setAttribute("password", nl.item(i).getAttributes().getNamedItem("password").getNodeValue());
noteuser.appendChild(n);
}

//add regist Node
Element n = d.createElement("user");
n.setAttribute("name", id);
n.setAttribute("password", pwd);
noteuser.appendChild(n);

//save data to file
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
DOMSource source = new DOMSource(d);

//file's path
StreamResult result = new StreamResult(new File("c:\\note-user.xml"));
transformer.transform(source, resu


相关文档:

java入门

 Java学习从入门到精通 
一、 JDK (Java Development Kit) 
JDK是整个Java的核心,包括了Java运行环境(Java Runtime Envirnment),一堆Java工具和Java基础的类库(rt.jar)。不论什么Java应用服务器实质都是内置了某个版本的JDK。因此掌握JDK是学好Java的第一步。最主流的J ......

JAVA实现的六色球

      这是JAVA中的一个作业,
      效果图:
      
       画框中共有六个球,它们碰到墙之后能够反弹,而且相互碰撞之后能相互碰撞。
       要用到的知识: ......

JAVA笔记(二)

在类中定义的方法在返回值前加上static修饰符就可以在main方法中调用了。如果不用static那就需要在main方法中创建对象,使用对象来调用对象的方法。
public class Test{
 public static void main(String[] args){
  Test t=new Test();
  int b=1;
  int c=2;
  int[] ......

JAVA反射小结

1  JAVA的反射,其实就是通过一个实例化的对象反过来去找到一个类的完整信息,比如对于如下的形式:
X x=new X();
   x.getClass().getName();
这里就会输出这个类所在的完整信息,即"包名.类名";
  最常用的三种实例化CLASS类对象
Class<?> c1 = null ;  // 指定泛型
  C ......

java设计模式 策略模式

定义:定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户。
适用性
许多相关的类仅仅是行为有异。“策略”提供了一种用多个行为中的一个行为来配置一个类的算法。
需要使用一个算法的不同变体。例如,你可能会定义一些反映不容的空间/时间权衡的算法。当这些变体实 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号