2015-06-27 92 views
0

我們正在以下異常,同時試圖獲得FileOutputStream中輸入文件名: java.lang.Exception的:/ var/tmp中(是一個目錄)獲取異常嘗試獲取FileOutputStream中

請建議什麼都可以錯誤的原因。

其中發生異常

代碼片段:

public static FileOutputStream getFileInternal() 
{ 
String pFilename = "/usr/tmp/"; 
File f = new File(pFilename); 
pFilename = f.getCanonicalPath(); 
FileOutputStream fo = null; 
fo = new FileOutputStream(pFilename, true); 
return fo; 
} 
+2

'/ usr/tmp /'不是文件名,使用不以'/'結尾的文件名, –

回答

1

"/usr/tmp/"是一個目錄。

FileOutputStream只寫入普通文件,而不是目錄。

你可以嘗試這樣的:

String pFilename = "/usr/tmp/output.txt"; 
// ... 
0

你不能從一個目錄中創建一個FileOutputStream。與File不同,它們只能用於實際文件。