在文本文件的开头写入 Java [英] Writing in the beginning of a text file 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:
- 创建一个新文件
- 给它写前缀
- 将数据从旧文件复制到新文件
- 将旧文件移动到备份位置
- 将新文件移动到旧文件所在的位置
- 可选择删除旧的备份文件
这篇关于在文本文件的开头写入 Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!