標籤:sys put pat 檔案 this div his new config
1, linux下的檔案分隔字元是‘/‘, windows下的檔案分隔字元為‘\‘。但是‘\‘這個符號是轉義符。如果需要在console輸出‘\‘這個符號的,你需要輸入‘\\‘。另外轉義符‘\‘還可以用雙引號的字元內部再次使用雙引號的這種情況,例如下面第三行。
@Test public void test$(){ System.out.println("\\"); System.out.println(‘/‘); System.out.println("\"為了轉義雙引號\""); #分別輸出 "\" , "/", "為了轉義雙引號" System.out.println("\") #編譯報錯 }
linux與windows環境下分隔字元的替換
//linux下的檔案分隔字元替換成window的分隔字元filePath = filePath.replace("/","\\");
2,在web項目中擷取當前項目的絕對路徑:
#tomcat項目擷取運行項目的絕對路徑String proPath = this.getClass().getResource("/").getPath().substring(1) ;#例如:proPath ="D:\projectname\project_parent\web\target\vsp-web\WEB-INF\classes"
3, 在java項目中擷取jar所在的當前路徑,並讀取jar包所在路徑下的配置資訊
#java項目打包成jar後,擷取jar當前路徑的位置,並向項目中匯入config.properties的設定檔Properties prop=new Properties();InputStream in=new FileInputStream(new File(System.getProperty("user.dir")+File.separator+"config.properties")); prop.load(in);
linux路徑分隔字元'/'與windows下的分隔字元'\\',以及java項目,web項目讀取項目的路徑