Reputation: 15
We are getting the following exception while trying to get FileOutputStream for a filename: java.lang.Exception: /var/tmp (Is a directory)
Please suggest what can be the cause of the error.
Code snippet where exception occurs:
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;
}
Upvotes: 0
Views: 86
Reputation: 8902
You cannot create a FileOutputStream
from a directory. Different from File
, they only work with actual files.
Upvotes: 0
Reputation: 53819
"/usr/tmp/"
is a directory.
FileOutputStream
only writes into regular files, not directories.
You can try something like:
String pFilename = "/usr/tmp/output.txt";
// ...
Upvotes: 1