Comment vérifier si un fichier existe en Java

Comment vérifier si un fichier existe en Java

Pour déterminer si un fichier existe dans votre système de fichiers, utilisez Java IOFile.exists().

package com.example.io;

import java.io.*;

public class FileChecker {

  public static void main(String args[]) {

      File f = new File("c:\\example.txt");

      if(f.exists()){
          System.out.println("File existed");
      }else{
          System.out.println("File not found!");
      }

  }

}