Pinky
Pinky

Reputation: 15

Getting exception while trying to get FileOutputStream

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

Answers (2)

Fred Porciúncula
Fred Porciúncula

Reputation: 8902

You cannot create a FileOutputStream from a directory. Different from File, they only work with actual files.

Upvotes: 0

Jean Logeart
Jean Logeart

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

Related Questions