简体   繁体   English

尝试获取FileOutputStream时获取异常

[英]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) 尝试获取文件名的FileOutputStream时遇到以下异常:java.lang.Exception:/ var / tmp(是目录)

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. "/usr/tmp/"是一个目录。

FileOutputStream only writes into regular files, not directories. FileOutputStream仅写入常规文件,而不写入目录。

You can try something like: 您可以尝试如下操作:

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

You cannot create a FileOutputStream from a directory. 您不能从目录创建FileOutputStream Different from File , they only work with actual files. File不同,它们仅适用于实际文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试从证书中获取私钥时出现异常 - Getting exception while trying to get the private key from certificate 尝试创建数据库连接时出现异常 - Getting exception while trying to create a database connection FileOutputStream中的FileNotFound异常 - FileNotFound Exception in FileOutputStream Android FileoutputStream NullPOinter 异常 - Android FileoutputStream NullPOinter Exception HttpsUrlConnection在GET请求时获取EOF异常 - HttpsUrlConnection getting EOF exception while GET request 在尝试获取deviceID时获取NullPointerException - Getting NullPointerException, while trying to get deviceID 在Java中尝试访问Web服务中的Web方法时获取远程异常 - Getting Remote Exception While trying to Access a webmethod in a webservice in java 尝试在画布纹理视图 android 上绘制时出现空指针异常? - Getting a null pointer exception while trying to draw on canvas textureview android? 尝试通过https调用服务时出现异常 - Getting Exception while trying to call a service over https 如何在 Spring 引导中使用 JPA 从数据库中获取特定列(尝试从数据库中获取特定列时出现异常)? - How to get specific columns from database using JPA in Spring Boot (Getting Exception while trying to fetch specific column from Database)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM