How can I remove the hidden attribute to a java file?

2
package com.resolvethis.nio;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.LinkOption;
import java.nio.file.Path;
import java.nio.file.Paths;

public class MakeFileHidden {


    public static void main(String[] args) {
        try {

            Path path = Paths.get("C:\Users\ITSAO\Documents\testfile.txt");
            Boolean hidden = (Boolean) Files.getAttribute(path, "dos:hidden" , LinkOption.NOFOLLOW_LINKS);

                         if (hidden != null && !hidden){
                         Files.setAttribute(path, "dos:hidden" , Boolean.TRUE, LinkOption.NOFOLLOW_LINKS);
                               System.out.println("File is now hidden!");   
        }
    }catch (IOException ex){
           System.err.println("Things went wrong: " + ex.getMessage());
           ex.printStackTrace();  

               }
           } 
      }

// Occupy this block of code to hide the file that I want to choose but I want to know what method or how can I make it visible again?

    
asked by Yhair Ramos 08.05.2018 в 23:44
source

1 answer

1

To remove the "hidden" property simply define the property with value "False":

Files.setAttribute(path, "dos:hidden" , Boolean.FALSE, LinkOption.NOFOLLOW_LINKS);

you can add this block of code:

 if (hidden != null && hidden){
         Files.setAttribute(path, "dos:hidden" , Boolean.FALSE, LinkOption.NOFOLLOW_LINKS);
         System.out.println("File is now visible!");           
     }

This way your file would no longer have the hidden property.

    
answered by 09.05.2018 в 20:24