以正确的顺序将数据追加到文件

编程入门 行业动态 更新时间:2024-10-25 22:24:08
本文介绍了以正确的顺序将数据追加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经使用"a +"模式创建了一个文件. 我想将数据写为该文件为 NU2947; 03/09/2004; NU2947; 03/09/2004; F50359; 03/06/2004; 但是我得到了 F50359; 03/06/2004; NU2947; 03/09/2004; 放入该文件. 谁能帮我在文件中写入重复数据. 还请告知我如何纠正输入数据的顺序/顺序. 在此先感谢.

Hi, I had created a file with "a+" mode. I want to write data into that file as NU2947;03/09/2004; NU2947;03/09/2004; F50359;03/06/2004; but I am getting F50359;03/06/2004; NU2947;03/09/2004; into that file. Can anyone help me out to write duplicate data in a file. Also let me know that how can I correct the sequence/order of input data. Thanks in advance.

推荐答案

答案很明显.您的代码(您未显示给我们的代码)以错误的顺序写入了数据.如果以正确的顺序编写它,它将以正确的顺序出现在文件中. The answer is obvious. Your code, the code you didn''t show us, is writing the data in the wrong order. If you write it in the right order, it will appear in the file, in the right order.

如果不选择代码,很难给出答案.但是,如果您必须能够在文件中的特定位置插入一行,就不用管它了.您只能在文件末尾附加信息.因此,如果您想执行类似的操作,最好的方法是将所有内容加载到内存中,将其排序在内存中,然后再次写入完整文件. Without seing your code, it is difficult to give an answer. However, if you have to be able to insert a line at a specific location in your file, forget about it. You can only append information at the end of the file. So, if you want to do something like that, the best way is to load everything in memory, sort it in memory and then write the full file once again.

更多推荐

以正确的顺序将数据追加到文件

本文发布于:2023-10-27 15:24:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:顺序   正确   文件   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!