使用序列化将我的对象序列化到硬盘驱动器 [英] using serialization to serialize my objects to hard drive
问题描述
嘿我正在使用序列化将我的对象序列化为硬盘驱动器,
读取它们没问题但是覆盖它们会导致我出现问题,我有点b / b
未经授权访问文件,但我给了文件夹所有的
权限。
来源:
http://www.vkarlsen.no/pastebin/default.asp?id=5545
有人能告诉我我做得不对吗
这只会在我写一个新文件时发生然后尝试重写它。
如果线程完成并启动overagain我能够覆盖已经存在的
文件,这是我想要的。
" Alexandre(www.pointnetsolutions.com)" < al ***************** @ gmail.com>
在留言中写道
news:11 *** *******************@f14g2000cwb.googlegr oups.com ...嘿我正在使用序列化将我的对象序列化为硬盘,<阅读它们没有问题,但覆盖它们会导致我出现问题,我有未授权访问文件但我给了该文件夹所有的权限。
来源:
http://www.vkarlsen.no/ pastebin / default.asp?id = 5545
有人能告诉我我做得不对
请准确发布异常消息。
您还应该发布完整的代码,说明您有什么问题,而不是像现在这样的一些方法。
Willy。
留言< 11 ********************** @ z14g2000cwz .googlegroups .com>,
"亚历山大(www.pointnetsolutions.com)" < al ***************** @ gmail.com>
写这只发生在我写一个新的文件,然后尝试重写它。
如果线程完成并启动overagain我能够覆盖已经存在的文件经常发生..
您使用文件流写入磁盘吗?是否在手动清理使用区块/
?以下示例不会出错。删除
''使用''块,你得到一个文件锁定异常:
"'System.IO类型的未处理异常。 IOException''发生在
mscorlib.dll
附加信息:进程无法访问文件I:\ x.dat
因为它被另一个进程使用。
static void Main(string [] args)
{
WriteFile();
WriteFile();
Console.Read();
}
static void WriteFile()
{
Foo foo = new Foo();
BinaryFormatter bf = new BinaryFormatter();
using(FileStream fs = new FileStream(@I:\ x.dat",FileMode.Create))
{
bf.Serialize (fs,foo);
}
}
-
Steve Walker
Hey im using serialization to serialize my objects to hard drive,
reading them is no problem but overwriting them causes me problems,i
have un authorized access to the files but i gave the folder all the
permissions.
source:
http://www.vkarlsen.no/pastebin/default.asp?id=5545
can someone tell me what im not doing right
this only occurs when i write a new file and then try to over write it.
if the thread finishes and starts overagain i am able to overwrite a
file that already exists as often as i want..
"Alexandre (www.pointnetsolutions.com)" <al*****************@gmail.com>
wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...Hey im using serialization to serialize my objects to hard drive,
reading them is no problem but overwriting them causes me problems,i
have un authorized access to the files but i gave the folder all the
permissions.
source:
http://www.vkarlsen.no/pastebin/default.asp?id=5545
can someone tell me what im not doing right
Please post the exact exception message.
You should also post the complete code that illustrates the problem you
have, not a few methods like you did now.
Willy.
In message <11**********************@z14g2000cwz.googlegroups .com>,
"Alexandre (www.pointnetsolutions.com)" <al*****************@gmail.com>
writesthis only occurs when i write a new file and then try to over write it.
if the thread finishes and starts overagain i am able to overwrite a
file that already exists as often as i want..
Are you using a filestream to write to disk? Is it in a using block /
being cleaned up manually? The example below does not error. Remove the
''using'' block, and you get a file locked exception:
"An unhandled exception of type ''System.IO.IOException'' occurred in
mscorlib.dll
Additional information: The process cannot access the file "I:\x.dat"
because it is being used by another process."
static void Main(string[] args)
{
WriteFile();
WriteFile();
Console.Read();
}
static void WriteFile()
{
Foo foo = new Foo();
BinaryFormatter bf = new BinaryFormatter();
using(FileStream fs = new FileStream(@"I:\x.dat",FileMode.Create))
{
bf.Serialize(fs,foo);
}
}
--
Steve Walker
这篇关于使用序列化将我的对象序列化到硬盘驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!