QuestionsJAVA: How to check file exists or not
mmSophia eve asked 2 weeks ago

File.exists()function check locatable file exists or not in your mentioned path. See below example:

import java.io.File;

public class Fileexists {
public static void main(String[] args) throws Exception{

// create new files
File fexist = new File(file_path);

// create new file in the system
fexist.createNewFile();

// if file exists
boolean bool = fexist.exists();
// this give you true if file exists or false not exists
System.out.println(“File exists: ” + bool);

}
}

Your Answer
Login
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.