11:删除文件夹下的所有目录: /* * 删除一个目录下的所有文件 */ public static void delAllFile(String path) { File file = new File(path); if(!file.exists()) return; if(!file.isDirectory()) return; String[] tempList = file.list(); File temp = null; for(int i = 0; i < tempList.length; i++) { if(path.endsWith(File.separator)) temp = new File(path + tempList[i]); else temp = new File(path + File.separator + tempList[i]); if(temp.isFile()) temp.delete(); if(temp.isDirectory()) delAllFile(path + tempList[i]); } } 12:字符串转换成时间及时间相减: 1:) SimpleDateFormat formatter = new SimpleDateFormat ("yyyy.MM.dd"); //假定像2002.07.04的是合法日期其他都非法。 String str="2002.07.04"; ParsePosition pos = new ParsePosition(0); Date dt=formatter.parse(str,pos); if(dt!=null) { //是合法日期 } else { //非法日期 } 2:) 两个日期相减 import java.util.*; import java.text.*; class a { public static void main(String[] args) { String s1 = "2003/08/15 17:15:30"; String s2 = "2002/09/14 14:18:37"; try{ SimpleDateFormat formatter = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss");
ParsePosition pos = new ParsePosition(0); ParsePosition pos1 = new ParsePosition(0); Date dt1=formatter.parse(s1,pos); Date dt2=formatter.parse(s2,pos1); System.out.PRintln("dt1="+dt1); System.out.println("dt2="+dt2); long l = dt1.getTime() - dt2.getTime();