How To Check File Exists In Java 10

By | April 15, 2018

This is a sample Java source code about “How To Check File Exists In Java 10”. To determine whether a file is exist in your file system, you can use the Java IO File.exists().

How To Check File Exists In Java 10

For example i am using java 10 with syntactic sugar keyword:

package com.cimblo.io;
import java.io.File;
public static void main(String[] args) {
   var out = System.out;
   var file = new File("D:\\cimblo.csv");

   if (file.exists()) {
      out.println("Cimblo.csv file is already exist");
   } else {
      out.println("Cimblo.csv file is not found!");
}

But if you still in lower Java SDK version, you can replace keyword “var” with “File”, that’s it.

Leave a Reply