【问题标题】:Hide subfolders inside a folder in java在java中隐藏文件夹内的子文件夹
【发布时间】:2015-12-23 18:44:21
【问题描述】:

我有一个场景,我需要隐藏一些包含一些文件的文件夹。 我在互联网上搜索了很多,但没有得到任何好的解决方案。 我需要隐藏子文件夹而不是整个目录。 这是我正在使用的代码

Process _p = null;
         try {
             _p = Runtime.getRuntime().exec("attrib +H " + t.getPath());
              _p.waitFor();
         } catch (IOException | InterruptedException ex) {
             java.util.logging.Logger.getLogger(newFrame.class.getName()).log(Level.SEVERE, null, ex);
         }

其中 t = 路径 tp 该文件 喜欢C:\parentFolder\subfolder1\subfolder2\book.xml
我只需要隐藏subfolder1\subfolder2\book.xml

请给我一些好的解决方案。

提前致谢。

【问题讨论】:

  • “隐藏”是什么意思?操作系统功能?
  • 是的,我需要隐藏子文件夹。
  • 那么你想通过 Java 来切换这个 OS 功能吗?
  • 这正是我想要做的。

标签: java io


【解决方案1】:

Java 7 解决方案

Path path = Paths.get("your/folder");
Files.setAttribute(path, "dos:hidden", true);

或者:

Path path = Paths.get("your/folder");
DosFileAttributeView attr = Files.getFileAttributeView(path, DosFileAttributeView.class);
attr.setHidden(true);

【讨论】:

    【解决方案2】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-07
    • 2017-06-06
    相关资源
    最近更新 更多