Sunday 21 August 2016

HOW TO CHECK IF FILE IS HIDDEN IN JAVA


public class HiddenFile {

    
// In Unix hidden file is begins with “.” And in Window is it “,”
   And it should not be directory,
   There is a method for cheking hidden file
                  Syntax of the method:

  public static boolean isHidden(Path path) throws IOException

     public static void main(String[] args) {
           String path = "D:/neeraj.txt";

           File file = new File(path);

           if (file.isHidden()) {
                System.out.println("file is hidden");
           } else {
                System.out.println("file is not hidden");
          }

     }

}


How To Append Text Into File In Java


//step 1. take path of file where you have to append text.
//step 2. create file object by keeping path in constructor of File
//step 3. create filewriter object to write the byte into file and true value means it will append text into file.
//step4. create BufferedWriter for better performance
//step 5. use append method and in last dont forget to close strem

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class AppendText {

            public static void main(String[] args) throws IOException {

                        String path = "D:/neeraj.txt";

                        File file = new File(path);

                        FileWriter fw = new FileWriter(file, true);

                        BufferedWriter bw = new BufferedWriter(fw);

                        fw.append(" how are you neeraj");
                        bw.close();

                        System.out.println("written");

            }


}