belongs to collection: Java File Handling Programs
Given a file and we have to find its attributes using java program.
Following packages are using here, to implement this program,
There are following two important classes, which are using this program to get the DOS based file attributes
The method readAttributes() of DosFileAttributeView is using to is using to get the Basic file attributes.
import java.nio.file.*; import java.nio.file.attribute.*; import java.util.Scanner; public class DosAttributeOfFile { public static void main(String[] args) throws Exception { // create object of scanner. Scanner KB = new Scanner(System.in); // enter path here. System.out.print("Enter the file path : "); String A = KB.next(); Path path = FileSystems.getDefault().getPath(A); // create object of dos attribute. DosFileAttributeView view = Files.getFileAttributeView(path, DosFileAttributeView.class); // this function read the attribute of dos file. DosFileAttributes attributes = view.readAttributes(); System.out.println("isArchive: " + attributes.isArchive()); System.out.println("isHidden: " + attributes.isHidden()); System.out.println("isReadOnly: " + attributes.isReadOnly()); System.out.println("isSystem: " + attributes.isSystem()); } }
Output
First run: Enter the file path : E:/JAVA isArchive: false isHidden: true isReadOnly: false isSystem: false Second run: Enter the file path : D:/Study isArchive: false isHidden: false isReadOnly: false isSystem: false
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program to get DOS based basic file attributes in java
Output