gpt4 book ai didi

java - 使用 Java 在 Linux 上查找给定文件的根目录

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:34:10 24 4
gpt4 key购买 nike

我正在尝试根据 specifications.freedesktop.org/trash-spec 在 Linux 上实现垃圾回收支持.它指出

It MAY also choose to provide trashing in the “top directories” of some or all mounted resources. This trashing is done in two ways, described below as (1) and (2).

(1) An administrator can create an $topdir/.Trash directory. The permissions on this directories should permit all users who can trash files at all to write in it.; and the “sticky bit” in the permissions must be set, if the file system supports it.

When trashing a file from a non-home partition/device4 , an implementation (if it supports trashing in top directories) MUST check for the presence of $topdir/.Trash.

如果我理解正确,我将需要找到 $topdir,根据我的理解,它是挂载文件系统/分区的根目录。

使用

FileStore store = FileSystems.getDefault().getFileStores();

我可以获得所有似乎是挂载点的FileStore,但我没有看到一个可靠的方式来获取挂载点作为文件路径 或字符串。

如何从(普通)Java 中找出挂载点?

最佳答案

根据您提供的链接,这是 $topdir 的准确描述

Top directory , $topdir — the directory where a file system is mounted. “/” is the top directory for the root file system, but not for the other mounted file systems. For example, separate file systems might be mounted on “/home”, “/media/flash”, etc. In this text, the designation “$topdir” is used for “any top directory”.

这个 question 的答案建议获取安装信息的方法,尽管我认为这是相当迂回的。希望这对您有所帮助!

关于java - 使用 Java 在 Linux 上查找给定文件的根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52344093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com