---
title: "Java创建隐藏文件"
author: "Java-Object"
date: "2013-06-27T00:17:10Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2013-06-27T00:17:10Z"
id: 1894951
url: "https://hezd.iteye.com/blog/1894951"
---

`import　java.io.File;`

`import　java.io.IOException;`

`　`

`public　class　设置文件属性　{`

`//　执行以下代码你将看到一个属性为隐藏的文件（D:ddd.ddd）`

`//　请到D盘下查看`

`public　static　void　main(String[]　args)　throws　IOException　{`

`//　创建新文件`

`File　file　=　new　File("D:\ddd.ddd");`

`　`

`//　删除文件并创建新文件`

`file.delete();`

`file.createNewFile();`

`　`

`//　拼dos命令`

`//　attrib的祥细功能介绍请在DOS内输入　"　attrib　/?　"　查看`

`String　sets　=　"attrib　+H　""　+　file.getAbsolutePath()　+　""";`

`//　输出命令串`

`System.out.println(sets);`

`//　运行命令串`

`Runtime.getRuntime().exec(sets);`

`}`

`}`

转载自：[http://tech.ddvip.com/2009-09/1253205754133387.html](http://tech.ddvip.com/2009-09/1253205754133387.html)