Java examples for File Path IO:File Attribute
Querying and Setting File Metadata
import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.DosFileAttributeView; public class Main { public static void main(String[] args) { Path path = FileSystems.getDefault().getPath("./file2.log"); try {/*from w ww. j a v a 2 s .co m*/ System.out.println("File Size:" + Files.size(path)); System.out.println("Is Directory:" + Files.isDirectory(path)); System.out.println("Is Regular File:" + Files.isRegularFile(path)); System.out.println("Is Symbolic Link:" + Files.isSymbolicLink(path)); System.out.println("Is Hidden:" + Files.isHidden(path)); System.out.println("Last Modified Time:" + Files.getLastModifiedTime(path)); System.out.println("Owner:" + Files.getOwner(path)); DosFileAttributeView view = Files.getFileAttributeView(path,DosFileAttributeView.class); System.out.println("\nDOS File Attributes\n------------------------------------\n"); System.out.println("Archive :" + view.readAttributes().isArchive()); System.out.println("Hidden :" + view.readAttributes().isHidden()); System.out.println("Read-only:" + view.readAttributes().isReadOnly()); System.out.println("System :" + view.readAttributes().isSystem()); view.setHidden(false); } catch (IOException e) { e.printStackTrace(); } } }