-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Michael Pozhidaev
committed
Feb 13, 2019
1 parent
3910277
commit c1c4c20
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Path file = ...; | ||
try { | ||
DosFileAttributes attr = Attributes.readDosFileAttributes(file); | ||
System.out.println("isReadOnly is " + attr.isReadOnly()); | ||
System.out.println("isHidden is " + attr.isHidden()); | ||
System.out.println("isArchive is " + attr.isArchive()); | ||
up vote 20 down System.out.println("isSystem is " + attr.isSystem()); | ||
vote } catch (IOException x) { | ||
System.err.println("DOS file attributes not supported:" + x); | ||
} | ||
|
||
|
||
http://openjdk.java.net/projects/nio/javadoc/java/nio/file/attribute/DosFileAttributeView.html | ||
|
||
|
||
|
||
Path path = ...; | ||
Boolean hidden = path.getAttribute("dos:hidden", LinkOption.NOFOLLOW_LINKS); | ||
if (hidden != null && !hidden) { | ||
path.setAttribute("dos:hidden", Boolean.TRUE, LinkOption.NOFOLLOW_LINKS); | ||
} | ||
|
||
|
||
//locate the full path to the file e.g. c:\a\b\Log.txt | ||
Path p = Paths.get("c:\\a\\b\\Log.txt"); | ||
|
||
//link file to DosFileAttributes | ||
DosFileAttributes dos = Files.readAttributes(p, DosFileAttributes.class); | ||
up vote 1 down | ||
vote //hide the Log file | ||
Files.setAttribute(p, "dos:hidden", true); | ||
|
||
System.out.println(dos.isHidden()); | ||
|
||
} | ||
} | ||
|
||
To check the file is hidden. Right-click on the file in question and you will see after the execution of the court that | ||
the file in question is truly hidden. | ||
|
||
enter im | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters