检索和替换文本文件中的数字 [英] Retrieving and Replacing number in text file

查看:23
本文介绍了检索和替换文本文件中的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检索和更改文本文件中的一个数字,该数字将位于第一行.它会改变长度,如4"、120"、78"来表示文本文件中保存的数据条目.

I need to retrieve and change a number in a text file that will be in the first line. It will change lengths such as "4", "120", "78" to represent the data entries held in the text file.

推荐答案

如果您需要更改第一行的长度,那么您将不得不读取整个文件并再次写入.我建议先写入一个新文件,然后在确定文件写入正确后重命名该文件,以避免在操作中途程序崩溃时丢失数据.

If you need to change the length of the first line then you are going to have to read the entire file and write it again. I'd recommend writing to a new file first and then renaming the file once you are sure it is written correctly to avoid data loss if the program crashes halfway through the operation.

这篇关于检索和替换文本文件中的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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