Crc32 access to a document check concise code of java

  Keyword: java, crc. 

  Jdk1.4 from the beginning, java core package has been provided to crc of support.    Here is a simple example, you want to help. 


  Import java.util.zip.CRC32; 
  Import java.util.zip.CheckedInputStream; 
  Import java.io.FileInputStream; 
  Import java.io.File; 

  / ** 
*
  * <p> Title: </ p> 
  * <p> Description: </ p> 
  * <p> Copyright: Copyright (c) 2003 </ p> 
  * <p> Company: www.jagie.com </ p> 
  * @ Author Jaige 
  * @ Version 1.0 
  * / 
  (Public class FileToCRCUtil 

  Public static String getFileCRCCode (File file) throws Exception ( 

  FileInputStream fileinputstream = new FileInputStream (file); 
  CRC32 crc32 = new CRC32 (); 
  For (CheckedInputStream checkedinputstream = 
  New CheckedInputStream (fileinputstream, crc32); 
  Checkedinputstream.read ()! = -1; 
  ) ( 
  ) 
  Return Long.toHexString (crc32.getValue ()); 


  ) 

  Public static void main (String [] args) throws Exception ( 

  File f = new File ( "c: \ \ YSFPCGL200311_237010400_JK.XML"); 
  System.err.println (getFileCRCCode (f)); 

  ) 

  ) 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Facebook
  • DotNetKicks
  • DZone
  • Netvouz
  • Propeller

Tags: ,

Releated Java Articles

Comments

Leave a Reply