Some codes that I don't know are collected.
1. byte [] data2 = "Welcome! I finally met you! ". GetBytes ();
Convert the content in the String type "" to a byte array directly, using the getBytes method of the String class.
2. String info = new String (byte [], 0, packet. getLength ());
Convert the content in the byte [] array to the String type. The code above indicates that the byte array reads the length of the array from 0, and convert the byte content of the array to the String type.
3.
Public static String RandomString (int length ){
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
Random random = new Random ();
StringBuffer buf = new StringBuffer ();
For (int I = 0; I <length; I ++ ){
Int num = random. nextInt (62 );
Buf. append (str. charAt (num ));
}
Return buf. toString ();
}
The method to generate a random array of length. The StringBuffer and String charAt methods are the same as the two binggo methods that were not used in the previous hard work.
4. Generate a time string in the specified format
Date date = new Date ();
SimpleDateFormat sdf = new SimpleDateFormat ("MM dd, yyyy ");
String s = sdf. format (date );