原文:分享非常有用的Java程序 (关键代码)(六)---解析/读取XML 文件(重要) XML文件 <?xml version="1.0"?> <students> <student> <name>John</name> <grade>B</grade> <age>12</age> </student> <student> <name>Mar…
原文:分享非常有用的Java程序(关键代码)(七)---抓屏程序 import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import java.io.File; ... public void captureScre…
原文:分享非常有用的Java程序 (关键代码)(五)---把 Array 转换成 Map import java.util.Map; import org.apache.commons.lang.ArrayUtils; public class Main { public static void main(String[] args) { String[][] countries = { { "United States", "New York" }, { &quo…
原文:分享非常有用的Java程序 (关键代码)(四)---动态改变数组的大小 /** * Reallocates an array with a new size, and copies the contents * * of the old array to the new array. * * @param oldArray the old array, to be reallocated. * * @param newSize the new array size. * * @return…
原文:分享非常有用的Java程序 (关键代码) (二)---列出文件和目录 File dir = new File("directoryName"); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i=0; i < children.length; i++) { // Get f…
原文:分享非常有用的Java程序 (关键代码) (三)---创建ZIP和JAR文件 import java.util.zip.*; import java.io.*; public class ZipIt { public static void main(String args[]) throws IOException { if (args.length < 2) { System.err.println("usage: java ZipIt Zip.zip file1 file2 f…
原文:分享非常有用的Java程序 (关键代码) (一)   分享一些非常有用的Java程序 (关键代码) ,希望对你有所帮助. 1.  得到当前方法的名字 String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); 2. 转字符串到日期 java.util.Date = java.text.DateFormat.getDateInstance().parse(date String); 或者是: S…
原文:分享非常有用的Java程序(关键代码)(八)---Java InputStream读取网络响应Response数据的方法!(重要) Java InputStream读取数据问题 ====================================================================== 原理讲解 1. 关于InputStream.read()      在从数据流里读取数据时,为图简单,经常用InputStream.read()方法.这个方法是从流里每次只读…
(1).request.getRealPath("/");//不推荐使用获取工程的根路径 (2).request.getRealPath(request.getRequestURI());//获取jsp的路径,这个方法比较好用,可以直接在servlet和jsp中使用 (3).request.getSession().getServletContext().getRealPath("/");//获取工程的根路径,这个方法比较好用,可以直接在servlet和jsp中使用…
jdom.jar下载地址1:http://www.jdom.org/downloads/ 下载地址2:http://www.java2s.com/Code/Jar/j/Downloadjdomjar.htm test.xml <?xml version="1.0" encoding="UTF-8"?> <HD> <disk name="C"> <capacity>8G</capacity>…