getcanonicalpath html里如何獲取file的絕對(duì)路徑?
html里如何獲取file的絕對(duì)路徑?第一:文件f=新文件(這個(gè).getClass().getResource(“/”).getPath())系統(tǒng)輸出打?。╢) 結(jié)果:C:documents and
html里如何獲取file的絕對(duì)路徑?
第一:文件f=新文件(這個(gè).getClass().getResource(“/”).getPath())系統(tǒng)輸出打?。╢) 結(jié)果:C:documents and settingsadministratorworkspaceProjectNamebin獲取當(dāng)前類的項(xiàng)目路徑。如果不添加“/”文件,f=新文件(這個(gè).getClass().getResource(“”).getPath())系統(tǒng)輸出打?。╢) 結(jié)果:C:documents And settingsadministratorworkspaceProjectNamebincomtest獲取當(dāng)前類的絕對(duì)路徑;第二:file directory=new file(“”)//參數(shù)為空字符串coursefile=目錄.getCanonicalPath() 系統(tǒng)輸出打?。╟oursefile)結(jié)果:C:documents and settingsadministratorworkspaceProjectName獲取當(dāng)前類的項(xiàng)目路徑。第三種方法是URL xmlpath=這個(gè).getClass().getClassLoader().getResource()選定.txt") 系統(tǒng)輸出打印(xmlpath)結(jié)果:file/C/documents and settings/administrator/workspace/ProjectName/bin/選定.txt獲取當(dāng)前項(xiàng)目SRC目錄選定.txt文件的路徑
文件類有兩個(gè)常見的方法獲取文件路徑,一個(gè)是getcanonicalpath(),另一個(gè)是getabsolutepath(),可以通過file類的實(shí)例調(diào)用