One, the CRC32 file is more test
A file check can ensure that the contents of the file are not tampered with, just in the work, recorded.
1 Private voiddochecksum (String fileName) {2 Try {3 4LOG.D ("checksum", fileName);5 6Checkedinputstream CIS =NULL;7 LongFileSize = 0;8 Try {9 //Computer CRC32 ChecksumTenCIS =NewCheckedinputstream ( One NewFileInputStream (FileName),NewCRC32 ()); A -FileSize =NewFile (fileName). Length (); - the}Catch(FileNotFoundException e) { -System.err.println ("File not found.")); -System.exit (1); - } + - byte[] buf =New byte[256]; + while(Cis.read (BUF) >= 0) { A at } - - //----------------------------------------------- - - LongChecksum =cis.getchecksum (). GetValue (); -Showtext = checksum + "+ fileSize +" +FileName; in - System.out.println (showtext); toLOG.D ("checksum", showtext); +Mhanler.sendemptymessage (1); - the *}Catch(IOException e) { $ e.printstacktrace ();Panax NotoginsengSystem.exit (1); - } the}
Second, Google Gson
Gson is quite handy for working with JSON data, and the example
1 Public classWechatconfig {2 Private intId;3 4 Public intgetId () {5 returnId;6 }7 Public voidSetId (intId) {8 This. Id =Id;9 }Ten One A -}
1 WeChat new WeChat (); 2 Wc.setid (+); 3 4 String json = mgson.tojson (WC); 5 6 {"Id": 20}
Reference: http://www.oschina.net/code/snippet_12_257
Http://www.cnblogs.com/haippy/archive/2012/05/20/2509329.html
Document verification and Google Gson use