可以通过 afp 安装锁定用 java 打开的文件吗?

发布于 2024-09-04 10:55:27 字数 725 浏览 0 评论 0原文

我试图通过 OSX 上的 Java 6 跨安装点获取文件锁:

    private void tryLockThroughShare() {
        String path = "/Volumes/Groups/mcm/javaTestInShare.txt";

        try {
            RandomAccessFile raf = new RandomAccessFile(path, "rw");
            FileLock flock = raf.getChannel().tryLock();
            System.out.printf("File %s is %s\n", path, (flock != null) ?
("locked") : ("not locked"));
            raf.write("yoo hoo!".getBytes());
            raf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

当我使用 AFP 或 SMB 挂载卷时,即使我可以写入文件 在安装的目的地中,我无法锁定它们,而是接收: IOException(不支持的操作)。

经过一些实验,我发现我可以在设置音量时锁定 使用 NFS。

有人找到了通过 SMB 或 AFP 安装锁定文件的方法吗?

I'm trying to get a file lock across a mount point via Java 6 on OSX:

    private void tryLockThroughShare() {
        String path = "/Volumes/Groups/mcm/javaTestInShare.txt";

        try {
            RandomAccessFile raf = new RandomAccessFile(path, "rw");
            FileLock flock = raf.getChannel().tryLock();
            System.out.printf("File %s is %s\n", path, (flock != null) ?
("locked") : ("not locked"));
            raf.write("yoo hoo!".getBytes());
            raf.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

When I mount a volume using either AFP or SMB, even though I can write files
in the mounted destination, I cannot lock them, receiving instead:
IOException (Operation not supported).

After some experimentation I found I could lock when the volume was setup
using NFS.

Has anyone found a way to lock a file across a SMB or AFP mount?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-09-11 10:55:27

您收到的异常说明了一切IOException(不支持操作)不同的文件系统具有不同的功能,锁定就是其中之一。维基百科文件系统比较虽然没有提到锁定,但确实清楚地说明了这一点。

当您通过 SMB 或 AFP 访问文件时,您实际上是在将它们用作文件系统,而它们是功能不是很丰富的文件系统。不幸的是,您不能假设存储文件的实际文件系统的所有功能都可以通过 SMB 或 AFP 获得。

SMB 协议的目标是提供对网络上文件、打印机等的共享访问,因为网络上的设备是异构的,所以该协议将其功能限制为最普遍支持的功能。

The exception you are getting says it all IOException (Operation not supported). Different file systems have different capabilities and locking is one of them. The Wikipedia Comparison of file systems though it does not mention locking really makes this point clear.

When you are accessing files via SMB or AFP you are effectively using those as the file system, and they are file systems that are not very rich in capabilities. Unfortunately you cannot assume that all the capabilities of the actual file system on which the files are stored will be available via SMB or AFP.

The goal of the SMB protocol is to provide shared access to files, printers and the like on a network, because devices on the network are heterogeneous the protocol limits its functionality to the most universally supported features.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文