import java.nio.file.Files; //导入方法依赖的package包/类

@Override

public void setFileHiddenAttribute(

String sourceFile,

boolean hidden ) {

sourceFile = IoUtils.normalizeFilePath(sourceFile, osType);

checkFileExistence(new File(sourceFile));

final String errMsg = "Could not " + (hidden

? "set"

: "unset")

+ " the hidden attribute of file '" + sourceFile + "'";

if (OperatingSystemType.getCurrentOsType().isWindows()) {

try {

Path path = Paths.get(sourceFile);

DosFileAttributes attr;

attr = Files.readAttributes(path, DosFileAttributes.class, LinkOption.NOFOLLOW_LINKS);

boolean goHidden = attr.isHidden();

if (!hidden && goHidden) {

Files.setAttribute(path, "dos:hidden", false, LinkOption.NOFOLLOW_LINKS);

} else if (hidden && !goHidden) {

Files.setAttribute(path, "dos:hidden", true, LinkOption.NOFOLLOW_LINKS);

}

} catch (IOException e) {

throw new FileSystemOperationException(errMsg, e);

}

} else if (OperatingSystemType.getCurrentOsType().isUnix()) {

// a '.' prefix makes the file hidden

String filePath = IoUtils.getFilePath(sourceFile);

String fileName = IoUtils.getFileName(sourceFile);

if (hidden) {

if (fileName.startsWith(".")) {

log.warn("File '" + sourceFile + "' is already hidden. No changes are made!");

return;

} else {

fileName = "." + fileName;

}

} else {

if (!fileName.startsWith(".")) {

log.warn("File '" + sourceFile + "' is already NOT hidden. No changes are made!");

return;

} else {

fileName = fileName.substring(1);

}

}

renameFile(sourceFile, filePath + fileName, false);

} else {

throw new FileSystemOperationException(errMsg + ": Unknown OS type");

}

}

java中setattribute_Java Files.setAttribute方法代码示例相关推荐

  1. cdate在java中_Java Calendar.add方法代码示例

    本文整理汇总了Java中java.util.Calendar.add方法的典型用法代码示例.如果您正苦于以下问题:Java Calendar.add方法的具体用法?Java Calendar.add怎 ...

  2. JAVA中rootpanel_Java JPanel.setFocusCycleRoot方法代码示例

    import javax.swing.JPanel; //导入方法依赖的package包/类 @Override public void actionPerformed(ActionEvent e) ...

  3. java中explore_Java ServerPlayer.exploreMap方法代码示例

    import net.sf.freecol.server.model.ServerPlayer; //导入方法依赖的package包/类 public void testHorsesLost() { ...

  4. java中mymaps_Java MyLocationStyle.myLocationType方法代码示例

    import com.amap.api.maps.model.MyLocationStyle; //导入方法依赖的package包/类 @Override protected void onCreat ...

  5. java中setDocument_Java ActionItem.setDocumentId方法代码示例

    import org.kuali.rice.kew.actionitem.ActionItem; //导入方法依赖的package包/类 @Test public void testConvertAc ...

  6. java中entry_Java FastMap.Entry方法代码示例

    import javolution.util.FastMap; //导入方法依赖的package包/类 protected void processXmlCAPDialog(XmlCAPDialog ...

  7. java中setcolor_Java XWPFRun.setColor方法代码示例

    import org.apache.poi.xwpf.usermodel.XWPFRun; //导入方法依赖的package包/类 /** * Inserts the given {@link Tem ...

  8. java中settext_Java JCheckBoxMenuItem.setText方法代码示例

    import javax.swing.JCheckBoxMenuItem; //导入方法依赖的package包/类 private void reloadLang() { lang = JLang.g ...

  9. java中setcolor_Java RPr.setColor方法代码示例

    import org.docx4j.wml.RPr; //导入方法依赖的package包/类 public RPr getRPrStyle(ObjectFactory factory, String ...

最新文章

  1. 最好的程序界面就是用户无需去阅读操作手册就知道该如何使用的界面
  2. Go 语言编程 — GC 垃圾回收
  3. 平行志愿计算机检索原理,通俗图解平行志愿,让你明白平行志愿检索规则
  4. Modbus通讯错误检测方法
  5. numpy 点乘_斯坦福CS217(六)Spatial点乘示例
  6. 【BZOJ2073】[POI2004]PRZ 状压DP
  7. 【C++深度剖析教程5】C++中类的静态成员函数
  8. DRBD+Corosync+Pacemaker+MySQL(下)
  9. 可可托海将打造研学旅游基地促经济发展
  10. JetBrains IDEs
  11. Windows创建新账户进行登录
  12. SQLiteDeveloper破解方法
  13. 基于智能电网的电力线载波通信研究
  14. [Essay]看《Re:从零开始的异世界生活》的一些感想
  15. error: Package requirements (sqlite3 > 3.7.4) were not met:
  16. Verilog语言程序框架
  17. c++中cout、cerr、clog的区别
  18. 单刀双掷的模拟开关MAX4544
  19. ArcEngine线分割面的实现方法
  20. openssh离线升级8.8

热门文章

  1. stylus基础教程,stylus实例教程,stylus语法总结
  2. 在3D建模中,ZBrush中的道具雕刻【案列教程】
  3. 怎么在echarts上多个y轴
  4. QQ群通过关键字查找不到在线客服申诉的办法
  5. 1行Python代码,把PPT转成图片,python-office功能更新~
  6. 前端之css grid网格布局
  7. 千元左右哪款蓝牙耳机好?音质超好的四款蓝牙耳机推荐
  8. C++文件操作解析及使用(读、写文件 使用文件指针)
  9. 只要一句话,为你生成创意画作
  10. Python OpenCV图像处理:❤️转换+梯度❤️边缘检测+图像融合,aplacian金字塔合成新物种