How can I determine if a file I want to read from actually exists?
Posted
by
Imray
on Stack Overflow
See other posts from Stack Overflow
or by Imray
Published on 2012-11-19T22:54:40Z
Indexed on
2012/11/19
23:00 UTC
Read the original article
Hit count: 258
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)?
© Stack Overflow or respective owner