File file=new File(filePath)報空指針

<pre name="code" class="java">剛開始代碼是這麼寫的:
String filePath = request.getSession(true).getServletContext().getRealPath("prCodeImages");
	        File prCodeFile = new File(filePath);
	        if(!prCodeFile .exists()  && !prCodeFile .isDirectory()){
	        	prCodeFile .mkdir(); 
	        }

本機運行沒問題,客戶那邊報
File prCodeFile = new File(filePath);這一行的空指針,
那就只有可能是<span style="font-family: Arial, Helvetica, sans-serif;">filePath這個變量的問題了。</span>
<span style="font-family: Arial, Helvetica, sans-serif;">以前沒接觸過這類問題,問了羣裏能人後才知道,linx系統和window系統是有區別的,獲取路徑方式不一樣,改成下面這樣:</span>

String filePath1 = request.getSession(true).getServletContext().getRealPath("/");
		String filePath = filePath1+"prCodeImages";
        File prCodeFile = new File(filePath);
        if(!prCodeFile .exists()  && !prCodeFile .isDirectory()){
        	prCodeFile .mkdir(); 
        }
就沒有問題了。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章