写一个文本文件开头的Java [英] Writing in the beginning of a text file Java

查看:165
本文介绍了写一个文本文件开头的Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在文本文件的开头写一些东西。我有一个包含内容的文本文件,我想在此内容之前写一些内容。说我有;

I need to write something into a text file's beginning. I have a text file with content and i want write something before this content. Say i have;


下午好,先生,你今天好吗?

我很好,你好吗?

感谢问,我很好

Good afternoon sir,how are you today?
I'm fine,how are you?
Thanks for asking,I'm great

修改后,我想要这样:

After modifying,I want it to be like this:


第1页 - 场景59

25.05.2011

Page 1-Scene 59
25.05.2011

下午好,先生,你今天好吗?

我很好,你好吗?

感谢问,我很好

Good afternoon sir,how are you today?
I'm fine,how are you?
Thanks for asking,I'm great

刚刚组成的内容:)我如何以这种方式修改文本文件?

Just made up the content :) How can i modify a text file like this way?

推荐答案

您不能以这种方式真正地修改 - 文件系统通常不允许您在任意位置插入数据,但您可以:

You can't really modify it that way - file systems don't generally let you insert data in arbitrary locations - but you can:


  • 创建新文件

  • 将前缀写入

  • 将数据从旧文件到新文件

  • 将旧文件移动到备份位置

  • 将新文件移动到旧文件文件的位置

  • 可选地删除旧的备份文件

  • Create a new file
  • Write the prefix to it
  • Copy the data from the old file to the new file
  • Move the old file to a backup location
  • Move the new file to the old file's location
  • Optionally delete the old backup file

这篇关于写一个文本文件开头的Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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