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;
}
"/usr/tmp/"
is a directory.
FileOutputStream
only writes into regular files, not directories.
You can try something like:
String pFilename = "/usr/tmp/output.txt";
// ...
You cannot create a FileOutputStream
from a directory. Different from File
, they only work with actual files.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.