How to open a plain text file in Java?

Java 8Object Oriented ProgrammingProgramming

You can access a plain text using the File class.

Example

Live Demo

import java.io.File;

public class ReadFile {
   public static void main(String[] args) {
      File f = null;
      String str = "data.txt";

      try {
         f = new File(str);
         boolean bool = f.canExecute();
         String a = f.getAbsolutePath();
         System.out.print(a);
         System.out.println(" is executable: "+ bool);
      } catch (Exception e) {
         e.printStackTrace();
      }
   }
}

Output

 C:\Users\data is executable: true
raja
Published on 12-Jan-2018 07:18:47
Advertisements