In this post we’ll write program to Find file is hidden or not till java 6 | also In java 7
- Program 1 to Find file is hidden or not in java 7 >
- Program 2 to Find file is hidden or not till java 6 >
Program 1 to Find file is hidden or not in java 7 >
java.nio.file.attribute.DosFileAttributes's isHidden() method can be used for finding whether file is hidden or not.
Method returns true - if file is hidden
Method returns false - if file isn't hidden
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.DosFileAttributeView;
import java.nio.file.attribute.DosFileAttributes;
/** JavaMadeSoEasy.com */
public class IsFileHiddenJava7 {
public static void main(String... args) throws IOException {
String fileName = "c:/myFile.txt";
// create java.nio.file.Path
Path path = Paths.get(fileName);
// create DosFileAttributeView and DosFileAttributes
DosFileAttributeView basicFileAttributeView = Files
.getFileAttributeView(path, DosFileAttributeView.class);
DosFileAttributes basicFileAttributes = basicFileAttributeView
.readAttributes();
//Is hidden?
boolean fileHidden = basicFileAttributes.isHidden();
if(fileHidden)
System.out.println(fileName+" is hidden ");
else
System.out.println(fileName+" isn't hidden ");
}
}
/* OUTPUT
c:/myFile.txt isn't hidden
*/
|
We must read other File operations like - create, copy, move, rename, delete, exist?, append, creation/lastModified/lastAccessed date, compare, size, Read only and writable.
Program 2 to Find file is hidden or not till java 6 >
java.io.File's isHidden() method can be used for finding whether file is hidden or not.
Method returns true - if file is hidden
Method returns false - if file isn't hidden
import java.io.File;
/** JavaMadeSoEasy.com */
public class IsFileHidden {
public static void main(String... args) {
String fileName = "c:/myFile.txt";
File file = new File(fileName);
boolean fileHidden = file.isHidden();
if(fileHidden)
System.out.println(fileName+" is hidden ");
else
System.out.println(fileName+" isn't hidden ");
}
}
/* OUTPUT
c:/myFile.txt isn't hidden
*/
|
RELATED LINKS>
Create File using createNewFile() method in java file IO
Program to Delete a file - in java file IO
Program to Hide and unHide File or Directory (by executing CMD commands in java program) till java6 - file IO
Program on How to hide and unHide file or Directory in java 7 using java.nio.file
Program to Find creation, last modification and last accessed date of file in date, month and year in java7 using java.nio.file
Labels:
Core Java
File IO/File handling