Time Processing:
Import Java.util.Date;
Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
public class datetool{
/**
* Convert Date (Chinese) to string (ms)
* @param date
* @param pattern
* @return
*/
public static String datetostring (Date date,string pattern) {
return new SimpleDateFormat (pattern). Format (date);
}
/**
* Convert string (milliseconds) to date (Chinese)
* @param datestring
* @param formate
* @return
* @throws ParseException
*/
public static Date stringtodate (String datestring,string formate) throws parseexception{
return new SimpleDateFormat (formate). Parse (datestring);
}
}
File processing:
Import Java.io.BufferedInputStream;
Import Java.io.BufferedOutputStream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class Iotool {
/**
* Byte stream loading and output
* @param srcfile
* @param destfile
*/
public static void function (File srcfile,file destfile) {
FileInputStream Fis=null;
FileOutputStream Fos=null;
try {
Fis=new FileInputStream (srcfile);
Fos=new FileOutputStream (destfile);
Byte[]bs=new byte[1024];
int length=0;
while ((Length=fis.read (BS))!=-1) {
Fos.write (BS, 0, length);
}
} catch (FileNotFoundException e) {
Todo:handle exception
E.printstacktrace ();
}catch (IOException e) {
Todo:handle exception
E.printstacktrace ();
}finally {
if (fis!=null) {
try {
Fis.close ();
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
}
if (fos!=null) {
try {
Fos.close ();
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
}
}
}
/**
* Character stream loading and output
* @param srcfile
* @param destfile
*/
public static void Function02 (File srcfile,file destfile) {
Bufferedinputstream Bis=null;
Bufferedoutputstream Bos=null;
try {
Bis=new Bufferedinputstream (New FileInputStream (srcfile));
Bos=new Bufferedoutputstream (New FileOutputStream (DestFile));
Byte[]bs=new byte[1024];
int length=0;
while ((Length=bis.read (BS))!=-1) {
Bos.write (bs,0,length);
}
} catch (FileNotFoundException e) {
Todo:handle exception
E.printstacktrace ();
}catch (IOException e) {
Todo:handle exception
E.printstacktrace ();
}finally {
if (bis!=null) {
try {
Bis.close ();
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
}
if (bos!=null) {
try {
Bos.close ();
} catch (IOException e) {
TODO Auto-generated catch block
E.printstacktrace ();
}
}
}
}
}
Tool class encapsulation (time conversion, document read/write)