javaÖÐʹÓÃÕýÔò±í´ïʽ
ת×Ô£ºhttp://student.csdn.net/space.php?uid=52781&do=blog&id=15267&cid=50252
javaÖÐʹÓÃÕýÔò±í´ïʽ
¼ÆËã»úרҵ±ÏÒµ»òÕßʹÓùýUnix¡¢PerlµÈ²úÆ·µÄ¶ÁÕßÒ»¶¨¶ÔÕýÔò±í´ïʽÓÐÒ»¶¨µÄÓ¡Ïó,¼´Ê¹Ã»ÓнӴ¥¹ýÕýÔò±í´ïʽҲ²»Òª±»ËüµÄÍâòËùÏŵ¹¡£ËäÈ»×öµ½¾«Í¨ÕýÔò±í´ïʽ±È½ÏÄÑ£¬µ«ÊÇÄܹ»ÕÆÎÕËüµÄ»ù±¾Ó¦ÓÃÈ´ÊǷdz£ÈÝÒ׵ģ¬Ò»µ©°ÑÕýÔò±í´ïʽӦÓÃÓÚʵ¼ÊÎÊÌâµÄ½â¾ö¾Í¿ÉÒԷdz£Ã÷ÏÔµÄÌá¸ß¹¤×÷ЧÂÊ¡£
ÕýÔò±í´ïʽ×îÔçÊÇÓÉÊýѧ¼ÒStephen KleeneÔÚ¶Ô×ÔÈ»ÓïÑԵĵÝÔöÑо¿³É¹ûµÄ»ù´¡ÉÏÌá³öÀ´µÄ£¬¾ßÓÐÍêÕûÓï·¨µÄÕýÔò±í´ïʽʹÓÃÔÚ×Ö·ûµÄ¸ñʽƥÅä·½ÃæÉÏ¡£ÕýÔò±í´ïʽÊÇÒ»ÖÖÃèÊöÎÄ×ÖģʽµÄ·½·¨£¬°üÀ¨Öظ´³öÏÖ¡¢²»Í¬Ñ¡Ôñ·½Ê½ÒÔ¼°ÎªÄ³Ð©×Ö·û(±ÈÈçÊý×Ö¡¢×Öĸ)¶øÌṩµÄËõдÐÎʽ¡£ÎÒÃǾ³£»áÅöµ½ÉõÖÁÓõ½Ëü£¬ÔÚWindowsµÄËÑË÷½çÃæÖÐÊäÈë“*.txt”¾Í¿ÉÒÔËÑË÷µ½ËùÓеÄÎı¾Îļþ£¬ÔÚDOSÌáʾ·ûÏÂÊäÈë“Dir *.exe”¾Í¿ÉÒÔÏÔʾ³öµ±Ç°Â·¾¶ÏÂËùÓеĿÉÖ´ÐÐÎļþ£¬ÔÚÊý¾Ý¿âÖмìË÷ËùÓÐÃû³ÆÖк¬ÓГtom”µÄ¼Ç¼¾Í¿ÉÒÔÖ´ÐÐÈçÏÂSQL£º“select * from T_Table where FName like ‘%tom%’”£¬ÕâЩ“*.txt”¡¢“%tom%”¾ÍÊÇÒ»ÖÖģʽ£¬ÕâЩģʽ½«»áÓëһЩÎı¾ÏàÆ¥Åä¡£
ΪʲôҪÓÃÕýÔò±í´ïʽ
ÄãÒ»¶¨×ö¹ý×Ö·û´®½âÎöµÄ¹¤×÷°É£¬ÄÇôÈÃÎÒÃÇÔÙÀ´ÖØÎÂÒ»ÏÂجÃΣ¡
¡¾Ø¬ÃÎ1¡¿“192.168.10.5[port=8080]”,Õâ¸ö×Ö·û´®±íʾIPµØַΪ192.168.10.5µÄ·þÎñÆ÷µÄ8080¶Ë¿ÚÊÇ´ò¿ªµÄ£¬ÇëÓóÌÐò½âÎö´Ë×Ö·û´®£¬È»ºó´òÓ¡³ö“IPµØַΪ***µÄ·þÎñÆ÷µÄ***¶Ë¿ÚÊÇ´ò¿ªµÄ”¡£
´úÂë 1.1 ÆÕͨ·½·¨½øÐÐIPµØÖ·×Ö·û´®½âÎö
String text = "192.168.10.5[port=8080]";
int leftBraceIndex = text.indexOf('[');
String ipAddr = text.substring(0,leftBraceIndex);
int equalsIndex = text.indexOf('=');
String port = text.substring(equalsIndex+1,text.length()-1);
System.out.println("IPµØַΪ"+ipAddr+"µÄ·þÎñÆ÷µÄ"+port+"¶Ë¿ÚÊÇ´ò¿ªµÄ");
ºÃÔÚ×Ö·û´®¸ñʽ²»¸´ÔÓ,Õâô¼òµ¥µÄÈÎÎñ»¹ÊÇÄÜÇáËɸ㶨µÄ¡£
¡¾Ø¬ÃÎ2¡¿ “192.168.10.5[port=21,type=ftp]”£¬Õâ¸ö×Ö·û´®±íʾIPµØַΪ192.168.10.5µÄ·þÎñÆ÷µÄ21¶Ë¿ÚÌṩµÄÊÇftp·þÎñ£¬ÆäÖÐÈç¹û“,type=ftp”²¿·Ö±»Ê¡ÂÔ£¬ÔòĬÈÏΪhttp·þÎñ¡£ÇëÓóÌÐò½âÎö´Ë×Ö·û´®£¬È»ºó´òÓ
Ïà¹ØÎĵµ£º
1.1 ²»ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀý
ÓÃnew¹Ø¼ü´Ê´´½¨ÀàµÄʵÀýʱ£¬¹¹Ô캯ÊýÁ´ÖеÄËùÓй¹Ô캯Êý¶¼»á±»×Ô¶¯µ÷Óᣵ«Èç¹ûÒ»¸ö¶ÔÏóʵÏÖÁËCloneable½Ó¿Ú£¬ÎÒÃÇ¿ÉÒÔµ÷ÓÃËüµÄclone()·½·¨¡£clone()·½·¨²»»áµ÷ÓÃÈκÎÀ๹Ô캯Êý¡£
ÔÚʹÓÃÉè¼Æģʽ£¨Design Pattern£©µÄ³¡ºÏ£¬Èç¹ûÓÃFactoryģʽ´´½¨¶ÔÏó£¬Ôò¸ÄÓÃclone()·½·¨´´½¨Ðµ ......
package com.chinacache.utils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
public class FileUtils {
private static final Logger logger = Logger.getLogger(FileUtils.class);
/**
* Òƶ¯Îļþµ½Ö¸¶¨Ä¿ ......
Java: class , objects
1 Inheritance(¼Ì³Ð)µÄ¹Ø¼ü×Öextends
class MountainBike extends Bicycle {
}
µ«ÊDz»ÄܶàÖؼ̳С£²»¹ý¿ÉÒÔͨ¹ýimplements¶à¸öinterfaceÀ´ÊµÏÖÀàËƵĶ«Î÷
2 interface
interface Bicycle {
void changeCadence(int newValue); // wheel rev ......
java.util Öеļ¯ºÏÀà°üº¬ Java ÖÐijЩ×î³£ÓõÄÀà¡£ ×î³£Óõļ¯ºÏÀàÊÇ List ºÍ Map¡£ List µÄ¾ßÌåʵÏÖ°üÀ¨ ArrayList ºÍ Vector£¬ËüÃÇÊǿɱä´óСµÄÁÐ±í£¬±È½ÏÊʺϹ¹½¨¡¢´æ´¢ºÍ²Ù×÷ÈκÎÀàÐͶÔÏóµÄÔªËØÁÐ±í¡£ List ÊÊÓÃÓÚ°´ÊýÖµË÷Òý·ÃÎÊÔªËصÄÇéÐΡ£
Map ÌṩÁËÒ»¸ö¸üͨÓõÄÔªËØ´æ´¢·½·¨¡£ Map ¼¯ºÏÀàÓÃÓÚ´æ´¢ÔªËØ ......
ÏàÐÅ´ó¼ÒƽʱÅöµ½¹ýһЩÔÚJAVAÖжÔͼÏñ½øÐд¦ÀíµÄÐèÇ󣬱ÈÈçÐèÒª¶ÔÉÏ´«µÄͼƬ¼ÓÉÏ×Ô¼ºµÄÇ©Ãû»òͼ±ê£¬»òÕßÉú³ÉºÍ½âÎö¶¯Ì¬µÄGIFͼƬ£¬ÒÔ¼°´¦ÀíPSDÎļþͼÏñÐÅÏ¢¡£±¾ÎľÍJAVAÔÚͼÏñ´¦ÀíÖÐһЩ»ù±¾Ó¦ÓýøÐÐÁ˽éÉÜ¡£Ï£Íûͨ¹ýÄܹ»¶Ô´ó¼ÒÔÚÒÔºóµÄͼÏñ´¦ÀíÖÐÓÐЩ°ïÖú¡£
Ò»¡¢¶ÔÒ»¸öÏÖÓеÄͼƬ½øÐÐÎ ......