如果文件不存在,Java的FileWriter对象是否会尝试创建文件? [英] Does Java's FileWriter object attempt to create a file if file does not exist?

查看:3489
本文介绍了如果文件不存在,Java的FileWriter对象是否会尝试创建文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想澄清Java API文档中有关FileWriter类的内容。该文档说明了以下内容:

I am seeking to clarify what the Java API documentation states about the FileWriter class. The documentation states the following:

constructor:
Constructs a FileWriter object given a file name.

public FileWriter(String fileName)
    throws IOException


fileName - String The system-dependent filename.

IOException - if the named file exists but is a directory rather than a
regular file, does not exist but cannot be created, or cannot be opened
or any other reason

我不清楚FileWriter对象是否会尝试创建fileName指定的文件字符串,虽然很明显,对象将检查文件是否已创建,如果无法创建则抛出异常。

It is not clear to me whether or not the FileWriter object will attempt to create the file specified by the fileName String, although it is clear that the object will check to see if the file is created and an exception thrown if it can not be created.

推荐答案

是的,它将被创建(如果它尚不存在。)如果无法创建文件,则抛出IOException。

Yes, it will be created (if it does not already exist.) If the file cannot be created, an IOException is thrown.

这篇关于如果文件不存在,Java的FileWriter对象是否会尝试创建文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆