簡體   English   中英

嘗試獲取FileOutputStream時獲取異常

[英]Getting exception while trying to get FileOutputStream

嘗試獲取文件名的FileOutputStream時遇到以下異常:java.lang.Exception:/ var / tmp(是目錄)

請提出可能導致錯誤的原因。

發生異常的代碼段:

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;
}

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

FileOutputStream僅寫入常規文件,而不寫入目錄。

您可以嘗試如下操作:

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

您不能從目錄創建FileOutputStream File不同,它們僅適用於實際文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM