java找不到指定路徑 JAVA獲取絕對路徑的問題如何解決?
JAVA獲取絕對路徑的問題如何解決?1使用servlet 1.1獲取項目的絕對路徑請求.getSession(). Getservletcontext()。Getrealpath(”)1.2獲取瀏覽器
JAVA獲取絕對路徑的問題如何解決?
1使用servlet 1.1獲取項目的絕對路徑請求.getSession(). Getservletcontext()。Getrealpath(”)1.
2獲取瀏覽器地址request.getRequestURL()1.
3獲取當前文件的絕對路徑請求.getSession().getServletContext().getRealPath(請求.getRequestURI()) 2. 獲取當前classpath字符串A2=類名class.getResource類(“”).toString()字符串a3=DBConnection.class.getResource(“/”).toString()字符串a4=DBConnection.class.getClassLoader().getResource(“”).toString()字符串t=線程.currentThread(). Getcontextclassloader()。獲取資源(“”)。Getpath()//可以很好地理解輸出。三。獲取文件t=線程.currentThread(). Getcontextclassloader()。獲取資源(“”)。Getpath()int num=t.indexof(”。Metadata”)字符串路徑=t.substring(1,Num)。替換(“/”,“ ”)“項目名稱webcontent文件”