JavaÏÂFile·¾¶ÎÊÌâ
ÓÐ2¸öÎÊÌâ ÔÚOSGI¿ò¼ÜÏ¿ª·¢bundle£¬ÓÃSystem.getProperty("user.dir")·µ»ØµÄÊÇ×ÀÃæµÄ·¾¶¶ø²»Êǵ±Ç°µÄ¹¤×÷Çø£¿ÕâÊÇΪʲô£¿ ʹÓÃclass.getClassLoader().getResourceÖ»ÄÜ·µ»ØURL»òInputStream£¬¿ÉÒÔͨ¹ý·µ»ØµÄURL»òInputStream´´½¨Ò»¸öFileô£¿(ʹÓÃURLµÄtoURIºÍtoString·µ»ØµÄ¶¼ÊÇ·Ç·¨Â·¾¶£¬´´½¨²»ÁËFile) ÁíÍ⻹ÓбðµÄ·½·¨¿ÉÒÔÈ¡µÃ¹¤×÷ÇøÂ·¾¶ÏµÄÅäÖÃÎļþ·¾¶Ã´£¿ ÕâÊÇÔÚ¿ª·¢ÖÐÓöµ½µÄ2¸öÎÊÌ⣬ϣÍûÄܵõ½´ïÈ˵Ļشð¡£
System.getProperty("user.dir")»ñÈ¡µÄÊÇJVMÅäÖõÄÊôÐÔ£¬ÓÐÄÚÖõĺÍ×Ô¼º¶¨ÒåµÄʹÓÃ-D´«È룬²»ÊÇ´«ÈëÎļþ·¾¶µÄ ʹÓÃMain.class.getClassLoader().getResourceAsStream("config.properties")»ñÈ¡µ±Ç°¹¤×÷È¥µÄÎļþ£¬×¼È·µÄÊÇclasspathÉϵÄÎļþÒýÓà ʹÓÃclass.getClassLoader().getResourceÖ»ÄÜ·µ»ØURL»òInputStream£¬¿ÉÒÔͨ¹ý·µ»ØµÄURL»òInputStream´´½¨Ò»¸öFileô£¿(ʹÓÃURLµÄtoURIºÍtoString·µ»ØµÄ¶¼ÊÇ·Ç·¨Â·¾¶£¬´´½¨²»ÁËFile) url.getFile() ×îºÃ²»ÒªÓÃSystem.getProperty("user.dir") URI.getFile()¾Í¿ÉÒÔÁË http://blog.csdn.net/swandragon/archive/2009/11/05/4770445.aspx µ«ÊÇclass.getClassLoader().getResourceAsStream("config.properties")·½·¨·µ»ØµÄÊÇÒ»¸öInputStream¶ÔÏó£¬ÎÒÏë»ñµÃÒ»¸öFile¶ÔÏ󣬺ýøÒ»²½µØ½øÐд¦Àí¡£¾ÍÊÇ˵£¬ÓÐʲô·½·¨Äܹ»»ñÈ¡¹¤×÷ÇøÏµÄÎļþ·¾¶£¬È»ºóÎҾͿÉÒÔ¸ù¾Ý·¾¶´´½¨Ò»¸öFile¶ÔÏ󣬻òÕßÓÐʲô·½·¨¿ÉÒÔÖ±½Ó»ñÈ¡ÅäÖÃÎļþµÄFile¶ÔÏó£¿ Ð
Ïà¹ØÎÊ´ð£º
import java.io.*; class FileTest { public static void main(String [] args) throws Exception { File fDir=new File(File.separator); String strFile="javaÔ´´úÂë²âÊÔ"+File.separato ......
ÓÃRandomAccessFileдÈëTXTÎļþ²é¿´Ê±ÊÇÂÒÂ룬ÇëÎÊÓÐʲô·½·¨¿ÉÒÔд³É¿É¶ÁµÄÎļþ£¬²»ÊÇÓÃÆäËûµÄÎļþ²Ù×÷£¬¾ÍÊÇÖ»ÓÃRandomAccessFileµÄ·½·¨ÊÇ·ñ¿ÉÒÔʵÏÖ£¿ Java code: import java.io.*; public class RandomAcce ......
import java.sql.Connection; import java.sql.Date; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class QueryTest&n ......
ÎÒÏÖÔÚÓÃstruts2¿ò¼Ü,ÐèҪʹÓÃajaxʵÏÖ¾Ö²¿Ë¢Ð£¬µ«ÊÇ´ÓÈÝÆ÷Àï·µ»ØµÄÖµ²»ÖªµÀÔõô´Óstruts.xmlÅäÖÃÎļþÀïÓ³Éäµ½jspÒ³ÃæÀÒÔǰservletÀïдout.orint("xxxxx")¾Í¿ÉÒԵõ½~£¬µ«ÊÇÏÖÔÚÓÃstruts¾Í²»ÖªµÀÔõôР......