读取同一文件会产生不同的值 [英] Reading Same file produces different values

查看:74
本文介绍了读取同一文件会产生不同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我创建一个字节数组,然后将一个字符串(256字节)和两个整数(使用BitConverter :: GetBytes())复制到其中。我使用File :: WriteAllBytes()将其保存到磁盘。然后我用File :: ReadAllBytes()读取它。如果我立即写下并阅读,一切正常。但是,如果我写,然后做一些其他的东西,然后读,字符串出来确定,但整数是不正确的。有任何想法吗?谢谢。


Vinoj

解决方案

这往往表明问题在于什么东西。你在写和读之间做。这个其他东西涉及什么?


有趣的是,其他东西只涉及读取文件(它是一个配置文件)并对它读取的内容运行操作。没有写操作。如果我终止程序并再次读取配置文件,它会正确读取(表明文件没有改变)。它仅在程序的单个实例中起作用。感谢。

好。尽管如此,如果没有代码示例试图诊断问题,那几乎是猜测。


Hi,

I create a byte array and then copy a string (256 bytes) and two integers (using BitConverter::GetBytes()) into it. I use File::WriteAllBytes() to save it to disk. Then I read it with File::ReadAllBytes(). If I write and read immediately following each other, everything works properly. However, if I write, then do some other stuff, then read, the string comes out ok, but the integers are not correct. Any ideas? Thanks.

Vinoj

解决方案

That would tend to suggest that the problem lies with whatever "stuff" you are doing in between the write and read. What does this other stuff involve?


The interesting thing is that the other stuff only involves reading the file (it''s a configuration file) and running operations on what it read. There are no write operations. If I kill the program and read the config file again, it reads correctly (indicating that the file hasn''t changed). It''s only within a single instance of the program that it acts up. Thanks.


Okay. Still, without a code sample trying to diagnose the problem is pretty much guesswork.


这篇关于读取同一文件会产生不同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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