¹ØÓÚ Java ¶ÔÏóÐòÁл¯Äú²»ÖªµÀµÄ 5 ¼þÊÂ
Java ÐòÁл¯¼ò½é
Java ¶ÔÏóÐòÁл¯ÊÇ JDK 1.1 ÖÐÒýÈëµÄÒ»×鿪´´ÐÔÌØÐÔÖ®Ò»£¬ÓÃÓÚ×÷ΪһÖÖ½« Java ¶ÔÏóµÄ״̬ת»»Îª×Ö½ÚÊý×飬ÒÔ±ã´æ´¢»ò´«ÊäµÄ»úÖÆ£¬ÒÔºó£¬ÈÔ¿ÉÒÔ½«×Ö½ÚÊý×éת»»»Ø Java ¶ÔÏóÔÓеÄ״̬¡£
ʵ¼ÊÉÏ£¬ÐòÁл¯µÄ˼ÏëÊÇ “¶³½á” ¶ÔÏó״̬£¬´«Êä¶ÔÏó״̬£¨Ð´µ½´ÅÅÌ¡¢Í¨¹ýÍøÂç´«ÊäµÈµÈ£©£¬È»ºó “½â¶³” ״̬£¬ÖØлñµÃ¿ÉÓÃµÄ Java ¶ÔÏó¡£ËùÓÐÕâЩÊÂÇéµÄ·¢ÉúÓеãÏñÊÇħÊõ£¬ÕâÒª¹é¹¦ÓÚ ObjectInputStream
/ObjectOutputStream
Àà¡¢ÍêÈ«±£ÕæµÄÔªÊý¾ÝÒÔ¼°³ÌÐòÔ±Ô¸ÒâÓà Serializable
±êʶ½Ó¿Ú±ê¼ÇËûÃǵÄÀ࣬´Ó¶ø “²ÎÓë” Õâ¸ö¹ý³Ì¡£
Çåµ¥ 1 ÏÔʾһ¸öʵÏÖ Serializable
µÄ Person
Àà¡£
Çåµ¥ 1. Serializable Person
package com.tedneward;
public class Person
implements java.io.Serializable
{
public Person(String fn, String ln, int a)
{
this.firstName = fn; this.lastName = ln; this.age = a;
}
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
public int getAge() { return age; }
public Person getSpouse() { return spouse; }
public void setFirstName(String value) { firstName = value; }
public void setLastName(String value) { lastName = value; }
public void setAge(int value) { age = value; }
public void setSpouse(Person value) { spouse = value; }
public String toString()
{
return "[Person: firstName=" + firstName +
" lastName=" + lastName +
" age=" + age +
" spouse=" + spouse.getFirstName() +
"]";
}
private String firstName;
private String lastName;
private int age;
private Person spouse;
}
½« Person
ÐòÁл¯ºó£¬ºÜÈÝÒ×½«¶ÔÏó״̬дµ½´ÅÅÌ£¬È»ºóÖØжÁ³öËü£¬ÏÂÃæµÄ JUnit 4 µ¥Ôª²âÊÔ¶Ô´Ë×öÁËÑÝʾ¡£
Çåµ¥ 2. ¶Ô Person ½øÐз´ÐòÁл¯
public class SerTest
{
@Test public void serializeToDisk()
{
try
{
com.tedneward.Person ted = new com.tedneward.Person("
Ïà¹ØÎĵµ£º
Java¶¯Ì¬´úÀíÀàλÓÚjava.lang.reflect°üÏ£¬Ò»°ãÖ÷ÒªÉæ¼°µ½ÒÔÏÂÁ½¸öÀࣺ
(1)Interface InvocationHandler£º¸Ã½Ó¿ÚÖнö¶¨ÒåÁËÒ»¸ö·½·¨
§public object invoke(Object obj,Method method, Object[] args)
ÔÚʵ¼ÊʹÓÃʱ£¬µÚÒ»¸ö²ÎÊýobjÒ»°ãÊÇÖ¸´úÀíÀ࣬methodÊDZ»´úÀíµÄ·½·¨£¬ÈçÉÏÀýÖеÄrequest()£¬argsΪ¸ ......
File£¨ÎļþÀࣩ
¾¡¹Üjava.io¶¨ÒåµÄ´ó¶àÊýÀàÊÇʵÐÐÁ÷ʽ²Ù×÷µÄ£¬FileÀ಻ÊÇ¡£ËüÖ±½Ó´¦ÀíÎļþºÍÎļþϵͳ¡£Ò²¾ÍÊÇ˵£¬FileÀàûÓÐÖ¸¶¨ÐÅÏ¢ÔõÑù´ÓÎļþ¶ÁÈ¡»òÏòÎļþ´æ´¢£»ËüÃèÊöÁËÎļþ±¾ÉíµÄÊôÐÔ¡£File¶ÔÏóÓÃÀ´»ñÈ¡»ò´¦ÀíÓë´ÅÅÌÎļþÏà¹ØµÄÐÅÏ¢£¬ÀýÈçȨÏÞ£¬Ê±¼ä£¬ÈÕÆÚºÍĿ¼·¾¶¡£´ËÍâ ......
ÔÚ±¾ÎÄͨ¹ýÌṩʹJava Ó¦ÓóÌÐò¿ÉÒÔʹÓà USB É豸µÄ API ¶øʹÕâ¸ö¹ý³Ì±äµÃ¸üÈÝÒ×.
Java ƽ̨һֱ¶¼ÒÔÆäƽ̨ÎÞ¹ØÐÔ×ÔºÀ¡£ËäÈ»ÕâÖÖÎÞ¹ØÐÔÓÐÐí¶àºÃ´¦£¬µ«ÊÇËüҲʹµÃ±àдÓëÓ²¼þ½»»¥µÄ Java Ó¦ÓóÌÐòµÄ¹ý³Ì±äµÃÏ൱¸´ÔÓ¡£ÔÚ±¾ÎÄÖУ¬Ñо¿¿Æѧ¼Ò½¯ÇåÒ°ÌÖÂÛÁËÁ½¸öÏîÄ¿£¬ËüÃÇͨ¹ýÌṩʹJava Ó¦ÓóÌÐò¿ÉÒÔʹÓà USB É豸µÄ API ¶øʹÕâ ......
ÔÚµ÷ÊÔµÄʱºò£¬Èç¹ûÒªÏÔʾbyteµÄÖµÊÇ·ñÓëÔ¤ÆÚÒ»Ö£¬Ò»°ãת»»Îª16½øÖƵÄ×Ö·û´®£¬»òÕßʹÓÃbase64ת»»ºó£¬È»ºóÏÔʾ³öÀ´¡£
/**
* ×Ö·û´®×ª»»³ÉÊ®Áù½øÖÆ×Ö·û´®
*/
public static String str2HexStr(String str) {
char[] chars = "0123456789ABCDEF".toCharArray();
StringBuilder sb = new StringBuilder("");
......