Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

JavaÍøÂç±à³Ì³õ²½

JavaÍøÂç±à³Ì³õ²½
Kagula
2009-11-23
¹Ø¼ü´Ê
Java  Socket  DataInputStream   DataOutputStream
¸ÅÒª
    ʹÓÃJavaͬ²½IOÓ¦ÓóÌÐò¿â£¬ÊµÏÖCS½á¹¹ÍøÂç±à³Ì¡£
ÕýÎÄ
ʹÓÃSocketÀ´½¨Á¢ÍøÂçÁ¬½Ó£¬Ê¹ÓÃDataInputStream¡¢DataOutputStreamÀ´´æÈ¡ÍøÂçÁ÷¡£
 
¿Í»§¶Ë²¿·Ý
µÚÒ»²½£º½¨Á¢ÍøÂçÁ¬½Ó¶ÔÏ󣬺ÍÍøÂçÁ÷ÊäÈëÊä³ö¶ÔÏó
Socket c = new Socket(InetAddress.getByName("192.168.0.144"),6009);
dis      = new DataInputStream(c.getInputStream());
dos      = new DataOutputStream(c.getOutputStream());
µÚ¶þ²½£º¶ÁдÍøÂçÁ÷
д×Ö·û´®ÓÃÏÂÃæµÄ´úÂë
dos.writeUTF(list.get(i).toString());
dos.flush();
д¶þ½øÖÆÊý¾Ý²ÉÓÃÏÂÃæµÄ´úÂë
//byte[] b = new byte[nnL];
dos.write(b,0,nnL);
dos.flush();
ÕâÀïҪעÒâµÄÊÇwriteº¯ÊýµÄµÚ¶þ¸ö²ÎÊý£¬Ö¸µÄÊÇ»º´æÇøÆðʼλÖã¬nnLÖ¸µÄÊÇ»º´æÇøÖÐÊý¾ÝµÄ³¤¶È¡£b»º´æµÄ´óС½¨ÒéΪ1KB£¬¹ý´ó»áµ¼Ö²¿·ÝÊý¾Ý·¢ËͳöÈ¥ÁË£¬µ«ÊǽÓÊÕµ½Ã»ÓÐÊÕµ½ÓÐЧµÄÊý¾Ý¡£
¶Á×Ö·û´®ÓÃÏÂÃæµÄ´úÂë
String sR = dis.readUTF();
¶Á¶þ½øÖÆÊý¾ÝÓÃÏÂÃæµÄ´úÂë
 
Dis.read(b,0,nnL);
ÕâÀïÐèҪעÒ⣬·¢ËͶËͬ½ÓÊÕ¶ËÖ®¼ä£¬ÍøÂçÁ÷´æÈ¡º¯ÊýҪƥÅ䣬Êý¾Ý³¤¶ÈҲҪƥÅ䣬·ñÔò»á×èÈû¡£
µÚÈý²½£º¹Ø±ÕÁ¬½Ó¡£´úÂëÈçÏÂ
Dis.close();
Dos.close();
C.close();
·þÎñ¶Ë²¿·Ý
     µÚÒ»²½£º½¨Á¢ServerSocket¶ÔÏ󣬵õ½¿Í»§¶ËµÄÁ¬½ÓÇëÇ󣬴úÂëÈçÏ£º
ServerSocket server = new ServerSocket(listenPort);
Socket incomingConnection = null;
while(true) {
   incomingConnection = server.accept();
   incomingConnection.setSoTimeout(9*60*1000);
   handleConnection(incomingConnection);
}
ÆäÖУ¬listenPortÊÇÕìÌý¶Ë¿ÚΪÕûÐÍ¡£¿Í»§Í¬·¢ËÍÇëÇóºó£¬·þÎñ¶ËºÍ¿Í»§¶Ë½¨Á¢Á¬½Ó£¬server.accept·µ»Øsocket¡£
ÀûÓÃsocket£¬µÃµ½¶ÁдÍøÂçÁ÷Êý¾ÝµÄ¶ÔÏó£¬ÆäËüͬ¿Í»§¶ËµÄ±à³Ì·½Ê½¡£ÔÚÍê³É¶ÁдºóÄãÒ²ÐèÒªµ÷ÓÃsocketʵÀýµÄcloseº¯Êý£¬¶Ï¿ªÍ¬¿Í»§¶ËµÄÁ¬½Ó¡£SocketʵÀýµÄsetSoTimeoutÉèÖ㬱£Ö¤ÔÚ¾ÅÃëºó×Ô¶¯¹Ø±Õͬ¿Í»§¶ËµÄÁ¬½Ó¡£
 
 
×ܽ᣺
Ïà±ÈC++£¬JavaÌṩµÄAPI·Ç³£ÈÝÒ×ʹÓᣵ«ÊÇҲҪעÒ⼸¸öÎÊÌâ¡£[1]·þÎñ¶ËºÍ¿Í»§¶ËµÄ¶Áдº¯Êý±ØÐëҪƥÅä¡£[2]·þÎñ¶Ëͬ¿Í»§¶ËÖ®¼ä¶


Ïà¹ØÎĵµ£º

JAVAÖеÄSingletonģʽ

µ¥Àýģʽ£¬¹ËÃû˼Ò壬ֻÄÜÓÐÒ»¸öʵÀý¡£
Ò».´Ó¶àḬ̈߳²È«ËµÆð£¬ÈçÏÂͼ´úÂ룬´ËÎÊÌâ¿ÉÒÔÓÃsynchronized¹Ø¼ü×ÖÀ´½â¾ö¡£¸Ã·½·¨È±µã£ºÃ¿Ò»¸öÏß³ÌÔÚ»ñȡʵÀý¶ÔÏó֮ǰ¶¼ÒªÔÚsynchronizedÉÏͬ²½µÄ¶ÔÏóÉϽøÐеȴý£¬Òò´ËЧÂʲ»¸ß¡£
¶þ.Double Check·½·¨£¬¼ûÏÂͼ´úÂë¡£Double CheckµÄ³õÖÔÊÇÖ»Óе±instanceΪNULLʱִÐеÄÏ̲߳ÅÐèÒªÔÚ ......

JavaÖÐÔõÑùÅжÏÒ»¸ö×Ö·û´®ÊÇ·ñÊÇÊý×Ö???

 ÔÚ±à³ÌµÄʱºò£¬¾­³£Óöµ½ÒªÅжÏÒ»¸ö×Ö·û´®ÖеÄ×Ö·ûÊÇ·ñÊÇÊý×Ö(0-9)
 ÏÂÃæÎÒ¸ø´ó¼Ò½éÉܼ¸ÖÖʵÏÖ·½·¨
1.ʹÓÃCharacter.isDigit(char)ÅжÏ
String str = "123abc";
if (!"".equals(str)) {
char num[] = str.toCharArray();//°Ñ×Ö·û´®×ª»»Îª×Ö·ûÊý×é
StringBuffer title = new StringBuffer();//ʹÓÃS ......

JAVA»·¾³Ê¹ÓÃÕýÔò±í´ïʽ´¦Àí×Ö·û´®

ÕýÔò±í´ïʽÊÇ×Ö·û´®´¦ÀíµÄÖÕ¼«ÎäÆ÷£¬±¾ÎÄÒÔÒ»¸ö¾ßÌåÌâÄ¿¼ò½éjava¶ÔÕýÔò±í´ïʽµÄÖ§³Ö¡£
ÌâÄ¿£º½«Ò»¸ö×Ö·û´®ÖеÄÐÎÈçhref=“XXXX”ºÍsrc=“XXXX”µÄ²¿·ÖÈ¡³ö£¬´òÓ¡¡£
´¦ÀíÕýÔò±í´ïʽÖ÷ÒªÓõ½java.util.regex.MatcherºÍjava.util.regex.PatternÁ½¸öÀà¡£
\\²âÊÔÓõÄ×Ö·û´®
String source= "...href=\" ......

java ²åÈëÊý¾Ýµ½ mysql ÂÒÂë ×î¼Ñ½â¾ö

 ÊÖ¶¯½¨±í£º
CREATE TABLE `excel` (
  `id` int(11) DEFAULT NULL,
  `name` varchar(50) DEFAULT NULL,
  `passwd` varchar(50) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gb2312;  ×¢ÒâÊÇgb2312
È»ºóÔÚÁ¬½ÓÊý¾Ý¿âʱ¼ÓÉÏ:
useUnicode=true&characterEncoding=gb2312.
¾ÍokÀ²£¡ ......

Java СÀý×Ó£ºÏÂÔز¢±£´æÍøÂçС˵

±¾Ê¾Àý´ÓÍøÉÏÏÂÔØÒ»±¾Ð¡Ëµ£¬²¢±£´æΪ UTF-8 ¸ñʽ¡£
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException; ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ