I’m learning Java, and I’m trying to write a program that can read from a .ser file, which I’ve already created with a writeTo() method.
I want to know a given file exists in the system before I tell the program to read from it.
My code looks like this:
public boolean readFromSerializedFile(String fileName){
FileInputStream fileInStream = null;
ObjectInputStream objectInStream = null;
try{
fileInStream = new FileInputStream(fileName);
objectInStream = new ObjectInputStream(fileInStream);
Is there a simple way I can determine if the file with the name of the parameter exists in the root directory (or wherever else specified)?
You can use File.exists() method.
Let’s suppose you want to know if file
abc.xmlexists. The following code illustrates how to do it.