Program on How to hide and unHide file or Directory in java 7 using java.nio.file






Program to hide file in java 7 using java.nio.file >



// Hide file;
Files.setAttribute(path, "dos:hidden", true);



import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;

/** JavaMadeSoEasy.com */
public class HideFileInJava7 {
   public static void main(String... args) throws IOException {
          String fileName = "c:/myFile.txt";
          File fileToBeHidden = new File(fileName);
          Path path = FileSystems.getDefault().getPath(fileName);

          // Hide file;
          Files.setAttribute(path, "dos:hidden", true);
 
          // Now, let's test whether file has been hidden or not
          boolean fileHidden = fileToBeHidden.isHidden();
          if (fileHidden)
                 System.out.println(fileName + " is hidden ");
          else
                 System.out.println(fileName + " isn't hidden ");
   }
}
/* OUTPUT
c:/myFile.txt renamed successfully to c:/myFileRenamed.txt
*/



unhide file in java 7 using java.nio.file >

// unHide file
Files.setAttribute(path, "dos:hidden", false);



RELATED LINKS>

Create File using createNewFile() method in java file IO


Copy a file in java 2 in ways - use org.apache.commons.io.FileUtils's copyDirectory(sourceDirectory, destDirectory)


Program to Move a file - in java file IO

Program to Rename a file - in java file IO


Program to Delete a file - in java file IO

Program to Make a file readable and writable in java



Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO


Copy a Directory





No comments:

Post a Comment