java ʹÓÃÏà¶Ô·¾¶¶ÁÈ¡Îļþ
http://www.blogjava.net/flysky19/articles/93492.html
1.java project»·¾³£¬Ê¹ÓÃjava.ioÓÃÏà¶Ô·¾¶¶ÁÈ¡ÎļþµÄÀý×Ó£º
*Ŀ¼½á¹¹£º
DecisionTree
|___src
|___com.decisiontree.SamplesReader.java
|___resource
|___train.txt,test.txt
*SamplesReader.java:
String filepath="resource/train.txt";//×¢ÒâfilepathµÄÄÚÈÝ£»
File file=new File(filepath);
……
*ÎÒÃÇÁôÒâfilepathµÄÄÚÈÝ£¬java.ioĬÈ϶¨Î»µ½µ±Ç°Óû§Ä¿Â¼("user.dir")Ï£¬¼´£º¹¤³Ì¸ùÄ¿
¼"D:\DecisionTree"Ï£¬Òò´Ë£¬´ËʱµÄÏà¶Ô·¾¶(ÒÔuser.dirΪ»ù·¾¶µÄ·¾¶)Ϊ"resource/train.txt"
¡£ÕâÑù£¬JVM¾Í¿ÉÒÔ¸ù¾Ý"user.dir"Óë"resource/train.txt"µÃµ½ÍêÕûµÄ·¾¶£¨¼´¾ø¶Ô·
¾¶£©"D:\DecisionTree\resource\train.txt"£¬´ÓÀ´ÕÒµ½train.txtÎļþ¡£
*×¢Ò⣺Ïà¶Ô·¾¶µÄÆðʼ´¦ÎÞб¸Ë"/";ÀýÈ磺
filepath="resource/train.txt";
¶ø²»ÊÇfilepath="/resource/train.txt"; //error!
2¡¢javaEE»·¾³£¬Ê¹ÓÃClassloaderÓÃÏà¶Ô·¾¶¶ÁÈ¡xmlµÄÀý×Ó£º
*²Î¼û֮ǰдµÄÎÄÕ“ͨ¹ýÐéÄâ·¾¶»òÏà¶Ô·¾¶¶ÁÈ¡Ò»¸öxmlÎļþ£¬±ÜÃâÓ²±àÂ딡£
*ÄÚÈÝÈçÏ£º
javaʹÓÃÏà¶Ô·¾¶¶ÁÈ¡xmlÎļþ£º
Ò»¡¢xmlÎļþÒ»°ãµÄ´æ·ÅλÖÃÓÐÈý¸ö£º
1.·ÅÔÚWEB-INFÏ£»
2.xmlÎļþ·ÅÔÚ/WEB-INF/classesĿ¼Ï»òclasspathµÄjar°üÖУ»
3.·ÅÔÚÓë½âÎöËüµÄjavaÀàͬһ¸ö°üÖУ¬²»Ò»¶¨ÊÇclasspath£»
¶þ¡¢Ïà¶ÔÓ¦µÄÁ½ÖÖʹÓÃÏà¶Ô·¾¶µÄ¶ÁÈ¡·½·¨£º
·½·¨Ò»£º£¨Î´ÑéÖ¤£©
½«xmlÎļþ·ÅÔÚWEB-INFĿ¼Ï£¬È»ºó
³ÌÐò´úÂ룺
InputStream is=getServletContext().getResourceAsStream( "/WEB-INF/xmlfile.xml" );
·½·¨¶þ£º½«xmlÎļþ·ÅÔÚ/WEB-INF/classesĿ¼Ï»òclasspathµÄjar°üÖУ¬Ôò¿ÉÒÔʹÓÃClassLoaderµÄ¾²Ì¬
·½·¨getSystemResourceAsStream(String s)¶ÁÈ¡£»
³ÌÐò´úÂ룺
String s_xmlpath="com/spf/web/ext/hotspot/hotspotxml/hotspot.xml";
InputStream in=ClassLoader.getSys
Ïà¹ØÎĵµ£º
ÕýÔò±í´ïʽÔÚ×Ö·û´®´¦ÀíÉÏÓÐ×ÅÇ¿´óµÄ¹¦ÄÜ£¬sunÔÚjdk1.4¼ÓÈëÁ˶ÔËüµÄÖ§³Ö
ÏÂÃæ¼òµ¥µÄ˵ÏÂËüµÄ4ÖÖ³£Óù¦ÄÜ£º
²éѯ£º
ÒÔÏÂÊÇ´úÂëƬ¶Î£º
String str="abc efg ABC";
String regEx="a|f"; //±íʾa»òf
Pattern p=Pattern.compile(regEx);
Matcher m=p.matcher(str);
boolean rs=m.find();
Èç¹ûstrÖÐÓÐregEx£¬ÄÇôrsΪtru ......
ÌâÄ¿¶¼ºÜ¼òµ¥,µ«ÓÐʱºòÈÃÄãÓñÊÍêÕûµÄд³öÀ´È´²»ÄÇôÈÝÒ×ÁË.
1.±éÀúÎļþ¼Ð(±»Õâ¸öÌâÄ¿¿¼ÁËÁ½´Î)
import java.io.File;
public class ListFile {
public static void main(String[] args) {
// TODO Auto-generated method stub
String path = "C:/Inetpub";
File f = new File(path);
list(f);
}
publ ......
JDBC¶ÁÈ¡Êý¾Ý¿âÔªÊý¾Ý,Éú³ÉJAVAʵÌåÀà
package com.nffish.util;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import com.nffish.c ......
Java°æÖ§¸¶±¦½Ó¿Ú¿ª·¢
ÐèÇ󣺵÷ÓÃÖ§¸¶±¦½Ó¿ÚµÄ½Ó¿Ú²¢¼¯³Éµ½É̳Ç
µ÷ÓÃÖ§¸¶±¦½Ó¿ÚËùÐèÒªµÄ“Ö§¸¶±¦ºÏ×÷»ï°éid”ºÍ“Ö§¸¶±¦°²È«Ð£ÑéÂ딹«Ë¾¶¼¸øÌṩºÃÁË£¬Ö§¸¶±¦¹Ù·½ÄÇÀïÒ²ÓиýӿڵēʵÎïÉÌÆ·½»Ò×·þÎñ¼¯³É¼¼ÊõÎĵµ”¼°Ïà¹ØµÄDEMOÔ´Âë¡£¹«Ë¾ÈÃÎÒÓÃJAVAÀ´Ð´£¬ÖÕÓÚÔÝʱ²»ÓÃÔÙдJSÁË£¬ºÙºÙ&hel ......
1.Java ¼¯ºÏ¿ò¼Üͼ
¡¡¡¡-¼¯ºÏ½Ó¿Ú£º6¸ö½Ó¿Ú£¨¶ÌÐéÏß±íʾ£©£¬±íʾ²»Í¬¼¯ºÏÀàÐÍ£¬ÊǼ¯ºÏ¿ò¼ÜµÄ»ù´¡¡£
¡¡¡¡-³éÏóÀࣺ5¸ö³éÏóÀࣨ³¤ÐéÏß±íʾ£©£¬¶Ô¼¯ºÏ½Ó¿ÚµÄ²¿·ÖʵÏÖ¡£¿ÉÀ©Õ¹Îª×Ô¶¨Ò弯ºÏÀà¡£
¡¡¡¡-ʵÏÖÀࣺ8¸öʵÏÖÀࣨʵÏß±íʾ£©£¬¶Ô½Ó¿ÚµÄ¾ßÌåʵÏÖ¡£
¡¡¡¡2.JavaÈÝÆ÷Àà½éÉÜ
¡¡¡¡¢Ù JavaÈÝÆ÷À඼¿ÉÒÔ×Ô¶¯µØµ÷Õû×Ô¼ºµÄ³ß´ ......