本文介绍了以正确的顺序将数据追加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用"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.
更多推荐
以正确的顺序将数据追加到文件
发布评论