ÁÉ­}ºô > IT§Þ³N Linux > ³Ì·s§ó·s
  IT¸ê°T·j¯Á
 
IT²£«~·j¯Á
[µ{¦¡¶}µo][ºôºÞ¥@¬É][ºô¸ô¦w¥þ][¼Æ¾Ú®w§Þ³N]
[§@·~¨t²Î][¹Å»«²á¤Ñ¡P½u¤W³X½Í][¬¡°Ê¶°ÀA]
[ºë±m±MÃD][Symantec±M°Ï][­q¾\IT§Þ³N¶g¥Z]
[¶}µo½×¾Â][ºôºÞ½×¾Â][¦w¥þ½×¾Â][¼Æ¾Ú®w½×¾Â]
[§@·~¨t²Î½×¾Â][Sybase±M°Ï][IBM dW§Þ³N±M°Ï]
[¯f¬r¨D§U][¯f¬r»Pº|¬}¼½³ø][¤åÀÉ¡P·½½X¤U¸ü]

¦p¦ó§Q¥ÎJavaµêÀÀUnix/Linuxªº¤å¥ó¸ô®|

µo§G®É¶¡¡G2007.09.25 06:27     ¨Ó·½¡GÁÉ­}ºô    §@ªÌ¡Gkit

¤j³¡¤Àªºjavaµ{¦¡À³¥Î©óUNIX/Linux¨t²Î¡A¦Óµ´¤j³¡¤Àªº¶}µo¬O¦bWindows¤U¡CÁöµM¡Ajava¥i¥H¹B¦æ¦banywhere, ¦ý²¦³ºÁÙ¦³«Ü¦hÀô¹Ò°t¸m°ÝÃD¡C

¨Ò¦p¦bUNIX¤U¡A§A»Ý­n±N¬Y¨Ç°t¸m¤å¥óªº¸ô®|¼g¤J¨ì¥t¤@­Ó°t¸m¤å¥ó¡C ¤]³\¦³«Ü¦h§½­­¡A¨Ï§A¥²¶·¼g¤Jµ´¹ï¸ô®|¡C

¦bconfig.propertiesùؼg¤J

logs = /logs/app/db/logs.properties

configs=/usr/WebSphere/AppServer/installedApps/appname/earname/warname/WEB-INF/properties/myconfig.properties

¦b¶}µo¶¥¬q¡A§A¬O§_Ä@·N¦b§AªºWindows¶}µo¾÷¤W«Ø¥ß¤W­±³o¼Ëªº¥Ø¿ý¡A©ÎªÌ³v­Ó­×§ï³o­Ó¸ô®|©O¡H ¤×¨ä¦b¤w¦³ªº¨t²Î¤U¡A¬°¤F¶}µo·sªº¥\¯à¡Aºc¿v¶}µoÀô¹Ò®É¡A³oºØ°t¸m¤å¥ó¸ô®|ªº­×§ï¬O¬Û·íªá®É¶¡ªº¡C ¨Ã¥B¡A¦bRelease®É¡A§A¥²¶·­n¨Ï¥ÎAnt¤u¨ã§å¶q­×§ï³o¨Ç°t¸m¤å¥ó¡C ¦ý§Ú¥i¥H»¡¡A¤j³¡¤À¶µ¥Ø¥u¦³µ¹¥Í²£©M¨t²Î¶°¦¨´ú¸ÕÀô¹Ò¤~·|°t¸mAnt¤u¨ã¡C¦Ó¦b§C¯Å§Oªº´ú¸ÕÀô¹Ò¤U¡A§A¥u¯à¤â°Ê§ó§ï¡C ¨º»ò¦p¦ó¤~¯à¤£­×§ï¥ô¦ó¤å¥ó¥i¥H¦Awindows¥»¦a½Õ¸Õ¨Ã¹B¦æ©O¡H

¤@¤U¡A§Úµ¹¥X¤@­Ó¤p¤p¤è®×¡C

1. ­«¼gjava.io.FileÃþ

¥ý¤£­n¦V§Ú¥á­»¿¼¥Ö¡A ­«¼gjava.io.File¨Ã¤£¤@©w­nÅܰÊrt.jar¤å¥ó¡C jvm¤ä´©pretend¡A¤]´N¬O°°¸Ë¡A§Ú¥i¥H§â§Ú­«¼gªºjava.io.File¦b¹B¦æ´Á®É¥N´Àrt.jar­ì¦³ªºjava.io.FileÃþ¡C ·Q¤F¸Ñ§ó¸Ô²Óªº¸ê°T¥i¥H¦b JAVA_HOMEùاä³o­Ó¤å¥ó¡G[ JAVA_HOME]\bin\client\Xusage.txt

-Xbootclasspath/p:

prepend in front of bootstrap class path

¦b½Õ¸Õ®É¡A§Ú´N¬O­n¥Î³o­Ó°Ñ¼Æ¡C°²³]¡A§Ú§â­«¼gªºjava.io.FileÃþ¤å¥ó¥´¥]¬°filemap_1_4.jar¡C½Õ¸Õ®É¡A§Ú´N¥i¥H¹B¦æ java -Xbootclasspath/p:D:\MyProject\FileMap/filemap_1_4.jar -cp ...

³o¼Ë¡A¦b§Ú½Õ¥Îªº©Ò¦³ÃþùØ¡A¯A¤Î¨ì¤å¥ó©Î¤å¥ó¨t²Î¥\¯à®É¡A³£½Õ¥ÎD:\MyProject\FileMap/filemap_1_4.jar ¤U­±ªºjava.io.File¦Ó¤£¬Ort.jar.

2. ¥\¯à¹ê²{

2.1 ¤å¥ó¥Ø¿ý¬M®gÃö«Y

¬°¤F¼W¥[¤@¨ÇÆF¬¡©Ê¡A §Ú¨Ï¥Î¤@­Ó¥Ø¿ý¬M®g¤å¥ó¡A¨Ó©w¸qUNIX/LINUX¤å¥ó¸ô®|©MWindows¤å¥ó¸ô®|ªº¬M®gÃö«Y¡C

¨Ò¦p¡Afilemap.properties

/usr/WebSphere/AppServer/installedApps/appname/earname/warname/=C:/MyProject/

/logs/app/db/=c:/MyProject/logs

·íµ{¦¡­nŪ¨ú/usr/WebSphere/AppServer/installedApps/appname/earname/warname/WEB-INF/properties/myconfig.properties

¤å¥ó®É¡Ajava.io.File·|¬M®g¨ìC:/MyProject/WEB-INF/properties/myconfig.properties¡C

2.2 java.io.File§ó§ï

¼W¥[¤@­ÓÀRºAÅÜ¼Æ private static HashMap filemaps=null;¥Î¨Ó«O¦s¬M®gÃö«Y¡C

¼W¥[¤@­Ó¨p¦³¤èªk initmapsªì©l¤Æ filemaps

/**
* read filemap.propreties to initialize file map.
*/
private void initmaps(){
if(filemaps==null){
filemaps=new HashMap();
String filemap=System.getProperty("filemap"); 
//Àò±ofilemap.properties¤å¥ó¸ô®|¡A»Ý­n¦bjvm¹B¦æ®É¶Ç¤J-Dfilemap=[filemap.properties¥þ¸ô®|¦W]¡A
¤£­n¸Õ¹Ï¨Ï¥Î classloader.getResource(), ¦]¬°getResourceùؤ]·|¨Ï¥Îjava.io.File¡A·|²£¥Íjvm²§±`¡C

if(filemap==null || filemap=="")
return;
this.path = fs.normalize(filemap); 
//·Ç³ÆÅª¨úfilemap.properties¤å¥ó¡C¦]¬°¨Ï¥ÎFileInputStream®É¡A
»Ý­n¶Ç¤J¤@­Ójava.io.File¹ï¶H¡A¦b³o¼È ®É§âthis.path³]¬°filemap.propertiesªº¸ô®|¡C

this.prefixLength = fs.prefixLength(this.path);
Properties pro=new Properties();
try {

pro.load(new FileInputStream(this)); //Ū¨úfilemap.properties.

Enumeration enumeration=pro.propertyNames();

while(enumeration.hasMoreElements()){
String sourcepath=(String)enumeration.nextElement(); 
String targetpath=pro.getProperty(sourcepath);
filemaps.put(sourcepath, targetpath); //«O¦s¨ìfilemapsÀRºA¹ï¶HùØ¡C
}
} catch(FileNotFoundException e1){
return;
} catch(IOException e2){
return;
}
} 
}

§Ú­ÌÁٻݭn¤@­Ó¨p¦³¤èªkÂà´«¸ô®|¡C

/**
* Get Virutal Path string
* @param name ­ìUNIX/Linux¸ô®|¡C
* @return ·swindows¸ô®|¡C
*/
private String getVirtualPath(String name){
Iterator sources=filemaps.keySet().iterator(); 
while(sources.hasNext()){
String source=(String)sources.next();
if(name.startsWith(source)==true){ 
//·í­ì¸ô®|¥]§tfilemapsùجY¤@­Ósource¸ô®|®É¡A±N­ì¸ô®|Âà´«¬°·sªºtarget¸ô®|¡C
String target=(String)filemaps.get(source);
name=target+name.substring(source.length());
}
} 
return name;
}

¦n¤F¡A²{¦b·Ç³Æ¦bjava.io.Fileùؽեγo¨â­Ó¤èªk¡C

/**
* Creates a new File instance by converting the given
* pathname string into an abstract pathname. If the given string is
* the empty string, then the result is the empty abstract pathname.
*
* @param pathname A pathname string
* @throws NullPointerException
* If the pathname argument is null
*/
public File(String pathname) {
//new function
initmaps();

if (pathname == null) {
throw new NullPointerException();
}
//new function
pathname=getVirtualPath(pathname);

this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}

public File(String parent, String child) {
//new function
initmaps();

if (child == null) {
throw new NullPointerException();
}
//new function
child=getVirtualPath(child);
parent=getVirtualPath(parent);

if (parent != null) {
if (parent.equals("")) {

this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {

this.path = fs.resolve(fs.normalize(parent),
fs.normalize(child));
}
} else {
this.path = fs.normalize(child);
}
this.prefixLength = fs.prefixLength(this.path);
}


public File(File parent, String child) {
//new function
initmaps();
child=getVirtualPath(child);

if (child == null) {
throw new NullPointerException();
}
if (parent != null) {
if (parent.path.equals("")) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
String parentpath=getVirtualPath(parent.path); 
this.path = fs.resolve(parent.path,
fs.normalize(child));
}
} else {
this.path = fs.normalize(child);
}
this.prefixLength = fs.prefixLength(this.path);
}

2.3 ¥´¥]

±Njava.io.File½sĶ¨Ã¥´¥]¦¨jar¤å¥ó¡C filemap_1_4.jar

2.4 ³]¸m½Õ¸ÕÀô¹Ò¡C

¦b§A»Ý­n½Õ¸ÕÀô¹Òùؤ£»Ý­n§â³o­Ójar¤å¥óµo¤Jclasspath¡A¦ý»Ý­n¦bVM arguments¨½¥[¤W

-Xbootclasspath/p:C:\MyProject\filemap_1_4.jar -Dfilemap=C:\MyProject\filemap.properties

3.´ú¸Õ

½s¼g´ú¸Õµ{¦¡

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
FileReader filereader;
try {
//¦C¦L/usr/WebSphere/AppServer/InstallApp/Test.java
filereader = new FileReader(
"/usr/WebSphere/AppServer/InstallApp/Test.java");
BufferedReader bufferedreader = new BufferedReader(filereader);
String line=null;
while((line=bufferedreader.readLine())!=null)
System.out.println(line);
//¹M¾ú/usr/WebSphere/AppServer/InstallApp/Test.java©Ò¦bªº¥Ø¿ý¤U©Ò¦³¤å¥ó¡A¨Ã¦C¦L¤å¥ó¦W¡C

File fl=new File("/usr/WebSphere/AppServer/InstallApp/Test.java");
String path=fl.getParent();
String[] files=new File(path).list();
for(int i=0;i System.out.println(files);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

¡]³d¥ô½s¿è¡G¶³¤l¡^


[ µoªíµû½× ] ¦rÅé[ ¤j¡B¤¤¡B¤p ] [ ¦C¦L ] [ ¶i¤J³Õ«È ] [ ¶i¤J½×¾Â ]  [ ±ÀÂ˵¹ªB¤Í ]
  ¡i¬ÛÃö¤å³¹¡j
¡P ¦p¦ó³q¹L¦ê¤f¨ÓºûÅ@Linux§@·~¨t²Îªº¥D¾÷ (09-24) ¡P SuSE Linux§@·~¨t²Î¤UApacheªº³]©w¤èªk (09-24)
¡P »s§@¦Û¤v­Ó©ÊªºLinux±Ò°ÊGRUB±Ò°Ê­I´º¹Ï¤ù (09-24) ¡P LinuxÀY¸£­·¼ÉFreemind vym rpm¦w¸Ë¤èªk (09-24)
¡P Linux¤º®Ö§ó·s¡GLinux Kernel 2.6.22.7 (09-24) ¡P Linux¨t²Î¶°¸s ¦w¸Ë°t¸m±Æ¿ùªº°ò¥»¤èªk (09-24)
¡P ·s¤â¾Ç°ó¡G´O¤J¦¡¨t²Î½sµ{¤¤ªº¥N½XÀu¤Æ (09-24) ¡P Openoffice¦U¤l¼Ò²Õªº½sͶ¶§Ç·§¬A¤¶²Ð (09-24)
¡P Ubuntu¬y´CÅ骺¤U¸ü»Pºô­¶¤º´O´CÅé¼½©ñ (09-24) ¡P CentOS4.4¥ÎVSFTPD¬[³]FTP¦øªA¾¹ªº¤èªk (09-24)
  ¡i«È¤á»Ý¨D¤ÏõXªí¡j
* ©m¡@¡@¦W:
§ó¦h¸ê®Æ¡@ ¤F¸Ñ¤è®×¡@ »{ÃѼt°Ó
* ³æ¦ì¦WºÙ:
* Ápô¹q¸Ü:
* ¹q¤l¶l¥ó:
  ÁÉ­}±ÀÂË  
  ¤â¾÷¡P¸ê¶O ¡P·s«~¡P¾ÉÁÊ¡Pµû´ú¡P¤â¾÷¸ê¶O¡P¼e±a
¤â¾÷·j¯Á  ¿Õ°ò¨È N73 MOTO Z6
  IT²£«~ ¡Pµ§°O¥»¡P»O¦¡¾÷¡P¦øªA¾¹¡P¦C¦L¡P§ë¼v
IT²£«~·j¯Á 
  IT§Þ³N ¡P¶}µo¡PºôºÞ¡P¦w¥þ¡P¼Æ¾Ú®w¡P§@·~¨t²Î
  ¸ê°T¤Æ ¡P¼öÂI¡P±MÃD¡P³X½Í¡P¶g¥Z¡P¤è®×®×¨Ò
[¬F°È][¹q«H][ª÷¿Ä][¹A·~][»s³y·~][¤¤¤p¥ø·~]
[CIO][ERP][¨ó¦P][ITºÞ²z][¤¤¶¡¥ó][¹q¤l°Ó°È]
[¬Fµ¦][¦a¤è][±M®a][µû¦ô][Ãã¨å][³Õ«È][ªÀ°Ï]
¡P ±MÃD:¤@¸ôºZ³qºc·Q¦±¡X¡XÅý¥X¦æ¤£¦A¾D¹J°ô¨®
¡P CIO¤u§@¿Ë¾ú:¥ø·~ERP¿ï«¬¤£¯à©¿µø"¿ï¤HÃö"
¡P ºî­z¡G¸ê°T¤Æ«Ø³]µ¹¤¤°êºÊº»±a¨Óªº¦UºØÅܤÆ
¡P ª÷¿Ä·~­·ÀIºÞ²z©Mªk³W¿í±q¦³¤­ÂI»Ý¦Ò¼{ªº¦]¯À
¡P «OÀI·~CIOÃöª`:¸Ó¦p¦ó«Ø¥ß²Î¤@°ª®ÄªºCRMÅé¨t
¡P ½Õ¬dÅã¥Ü¡G¦h¼ÆCIO¹ïIT³W¹º¤´¦s¦b§x´b©M»~¸Ñ
  ³Õ«È¡P½×¾Â ¡P´¿¼C¬î¡P¶µ¥ß­è¡PJava¾Ç²ß¡PºôºÞ