java SocketµÄ¹ÖÒìÖ®´¦
¹ÖÒìÖ®Ò»£º
connect(SocketAddress endpoint):Õâ¸ö·½·¨£¬³¢ÊÔÁ¬½Óserver¶Ë£¬Èç¹ûÁ¬½Ó²»ÉÏ£¬¾ÍÅ׳öIOExceptionÒì³£¡£Èç¹ûÁ¬½Ó³É¹¦ÁË£¬¾Í¼ÌÐøÖ´ÐÐÏÂÒ»²½µÄ´úÂë¡£
¹ÖÒìÖ®¶þ£º
boolean isConnected() :Õâ¸ö·½·¨µÄ½á¹û½ö½ö´ú±íÕâ¸ösocketÔø¾³É¹¦Á¬½Óµ½ÁËserver£¬µ«²¢²»±íʾÏÖÔÚÕâ¸öʱ¿ÌËüºÍserverÈÔ±£³ÖÁ¬½Ó״̬¡£
ÓÐÐĵÄÈ˻ᷢÏÖ£¬¼´Ê¹ÄãÒѾÇжÏÁËserverºÍsocketÖ®¼äµÄÁ¬½Ó£¨±ÈÈçserver downµôÁË»òÍøÂçÖжÏÁË£©,µ«ÊÇÕâ¸öº¯ÊýÖ´ÐеĽá¹ûÈÔ¾ÉÊÇtrue¡£ËùÒÔ£¬ÎÒÈÏΪÕâ¸ö·½·¨²¢²»ÏñÎÒÃÇÏëÏóÖеÄÄÇô“¹ÜÓÔ¡£
¹ÖÒìÖ®Èý£º
¿¼ÂÇÕâÑùÒ»ÖÖÇé¿ö£º
1.socketºÍserver socketÒѾ½¨Á¢ÁËÁ¬½Ó
2.µ«ÊÇÓÉÓÚÍøÂçÔÒò£¬Õâ¸öʱºòÁ¬½ÓÖжÏÁË¡£´ó¶àÊýϵͳ¶¼»áÓÐÒ»¸ö¶ÏÏßÖØÁ¬µÄ¹¦ÄÜ¡£
µ«Êǵ±Äãµ÷ÊÔʱ£¬Äã¿ÉÄܻᷢÏÖ£ºÍøÂç»Ö¸´Õý³£ºó£¬ÓÃÕâ¸ösocketÖØÐÂÁ¬½ÓserverSocket£¬È´ÔõôҲÁ¬²»ÉÏ¡£
ÔÚÕâÀïÎÒµÄ×ö·¨ÊÇ£º
socket=null;
//È»ºóн¨socket£¬¶ø²»ÊÇÓÃÔÀ´µÄÄǸösocket
socket = new Socket();
//½ÓÏÂÀ´£¬ÓÃÕâ¸ösocketÔÙÈ¥Á¬½ÓserverSocket£¬¾Í¿ÉÒԳɹ¦Á¬ÉÏÁË¡£
Ïà¹ØÎĵµ£º
ת×Ô£ºhttp://blog.163.com/gordonkkk/blog/static/63425684200962795039630/
´ÓCSDNÉÏ¿´µ½Ò»ÆªÅúÆÀJavaÓïÑÔÖî¶àÎÊÌâµÄ·ÒëÎÄÕ£¬ÔÎÄ×÷ÕßÊÇMario Fusco¡£ËûÖ¸³öÁËJavaÓïÑÔÂäºóÓÚʱ´ú£¬»ýÖØÄÑ·µµÄ10¸öÎÊÌâ¡£¿´¹ýÖ®ºóÒýÆðÁËÎÒµÄһЩÁªÏë¡£ÏÂÃæÁгöËûËù˵µÄ10´óÎÊÌâ¡£½Û»ÆÉ«×ÖÌåÊÇÎÒÒ»µãµã²»³ÉÊìµÄ˼¿¼¡£
1¡¢È±ÉÙ±Õ°ü£¨clos ......
µÚÒ»£¬Ì¸Ì¸final, finally, finalizeµÄÇø±ð¡£
¡¡final ÓÃÓÚÉùÃ÷ÊôÐÔ£¬·½·¨ºÍÀ࣬·Ö±ð±íʾÊôÐÔ²»¿É±ä£¬·½·¨²»¿É¸²¸Ç£¬À಻¿É¼Ì³Ð¡£finallyÊÇÒì³£´¦ÀíÓï¾ä½á¹¹µÄÒ»²¿·Ö£¬±íʾ×ÜÊÇÖ´ÐС£finalizeÊÇ ObjectÀàµÄÒ»¸ö·½·¨£¬ÔÚÀ¬»øÊÕ¼¯Æ÷Ö´ÐеÄʱºò»áµ÷Óñ»»ØÊÕ¶ÔÏóµÄ´Ë·½·¨£¬¿ÉÒÔ¸²¸Ç´Ë·½·¨ÌṩÀ¬»øÊÕ¼¯Ê± ......
Ò».javaÀà
package com.java.test;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
public class JavaReadXml {
// Document¿ÉÒÔ¿´×÷ÊÇXMLÔÚÄÚ´æÖеÄÒ»¸ ......
ÔÚʵ¼ÊÏîÄ¿Öиø¶¨Ò»Îļþ¼Ð£¬µÃµ½Õâ¸öÎļþ¼ÐÏÂËùÓеÄÎļþÕâÑùµÄÐèÇó²¢²»ÊǺܶ࣬¸ü¶àµÄÊDzéÕÒ»òÊÇɾ³ýijһ¾ßÌåµÄÎļþ
import java.io.File;
import java.util.ArrayList;
public class FileTest {
private static ArrayList<String> filelist = new ArrayList<String>();
public stati ......
public class Path {
//get class absolute address
public String getPath() {
String classPath = getClass().getName();
if (classPath.indexOf(".") != -1) {
classPath = classPath.substring(classPath.lastIndexOf(".") + 1,
......