Java大神教你如何隐藏文件?
下文笔者讲述使用java代码将指定文件设置为隐藏文件的方法分享,如下所示
Java设置文件隐藏的实现思路: 1.定义一个 隐藏文件的批处理命令 2.使用Runtime.getRuntime().exec运行批处理命令 即可实现隐藏文件的效果例:将D盘的Test文件设置为隐藏效果
import java.io.File; import java.io.IOException; public class TestClass { public static void main(String[] args) { File file = new File("D:" + File.separator + "test.txt"); try { file.createNewFile(); // R : 只读文件属性。A:存档文件属性。S:系统文件属性。H:隐藏文件属性。 String sets = "attrib +H \"" + file.getAbsolutePath() + "\""; System.out.println(sets); // 运行命令 Runtime.getRuntime().exec(sets); } catch (IOException e) { e.printStackTrace(); } } }

版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。