首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用fileWriter命令ReWriting一行

使用fileWriter命令ReWriting一行
EN

Stack Overflow用户
提问于 2013-07-04 22:06:03
回答 1查看 343关注 0票数 1

我是java新手,我有一个在txt文件上写信息的程序,唯一的问题似乎是,如果fileWriter附加了我不能编辑的文件,或者重写了文件上的特定行,有没有办法将写入器设置为从文件的开头开始,而不是在不擦除数据的情况下从结尾开始?因为这样我就不能编辑文件中的信息了。提前感谢您的回复!

EN

回答 1

Stack Overflow用户

发布于 2013-07-04 22:18:07

FileWriter类有几个构造函数。其中一些带有类型为boolean的"append“参数。您是否在true中使用了这些构造函数之一?

您应该对该参数使用false

代码语言:javascript
复制
    /**
 * Constructs a FileWriter object given a File object. If the second
 * argument is <code>true</code>, then bytes will be written to the end
 * of the file rather than the beginning.
 *
 * @param file  a File object to write to
 * @param     append    if <code>true</code>, then bytes will be written
 *                      to the end of the file rather than the beginning
 * @throws IOException  if the file exists but is a directory rather than
 *                  a regular file, does not exist but cannot be created,
 *                  or cannot be opened for any other reason
 * @since 1.4
 */
public FileWriter(File file, boolean append) throws IOException {
    super(new FileOutputStream(file, append));
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17472391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档