Topic: 如何在写一个文件拒绝别的进程访问此文件?

  Print this page

1.如何在写一个文件拒绝别的进程访问此文件? Copy to clipboard
Posted by: bluebangbang
Posted on: 2004-04-20 14:07


2.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: jigsaw
Posted on: 2004-04-20 15:35

如果文件不是很大 可以读入内存 然后把这个文件删除
处理完毕后 写回硬盘

3.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: jigsaw] Copy to clipboard
Posted by: PrimeJava
Posted on: 2004-04-20 17:06

jigsaw wrote:
如果文件不是很大 可以读入内存 然后把这个文件删除
处理完毕后 写回硬盘

如果遇到突然停电那不是糟了!

4.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: tian_cookie
Posted on: 2004-04-20 17:33

用NIO可以得到文件锁

5.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: floater
Posted on: 2004-04-20 21:49

This is more of a system task because we have no control of other threads. Try to rename/hide this file, instead.

6.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: dorrenchen
Posted on: 2004-04-20 23:02

assuming all threads access the file the same way and you write all those threads. Then you can do it like how microsoft word works. For mydoc.txt, create a lock file ~mydoc.txt, which stores lock info (like whether it's currently locked and who, etc). Then check that lock file before accessing the actual file. After current user closed file, delete lock file.

That's how I would do it.

7.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: bluebangbang
Posted on: 2004-04-21 16:02

Thanks for all

8.Re:如何在写一个文件拒绝别的进程访问此文件? [Re: bluebangbang] Copy to clipboard
Posted by: huangjiacai
Posted on: 2004-05-04 12:55

用线程同步机制
可以使一个线程在访问一个文件是防止其他线程中断它直到那线程stop的时候才可被其他线程访问


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923