title: Detect if the file exists
body: <p>Well the file "MyStore.obj" was attached along with the sheet I downloaded. And i'm supposed to read this file's content which is given with order of the contents.how can i make sure if it exists or not? because as you can see i tried using the method exists() but it didn't work </p>
  
  <pre><code>import java.io.*;
  
  public class sheet{
  public static void main(String[]args){
  try{
  FileInputStream fis=new FileInputStream("MyStore.obj");
  
  if(("MyStore.obj").exists()==false) //what can i do to fix this?
  
  throw new FileNotFoundException("file doesn't exist");
  
  ObjectInputStream ois=new ObjectInputStream(fis);
  
  int numOfStorageDevice=ois.readInt();
  int numOfComputerGames=ois.readInt();
  
  StorageDevice [] sd=new StorageDevice[numOfStorageDevice];
  
  for(int n=0;n&lt;numOfStorageDevice;n++)
   sd[n]=(StorageDevice)ois.readObject();
  
   ComputerGame []cg=new ComputerGame[numOfComputerGames];
  
   for(int m=0;m&lt;numOfComputerGames;m++)
  
   cg[m]=(ComputerGame)ois.readObject();
  
     File file=new File("Result.txt");
      FileOutputStream fos=new FileOutputStream(file);
     PrintWriter pr=new PrintWriter(fos);
  
   for(int i=0;i&lt;numOfStorageDevice;i++){
  
   String model= sd[i].getmodel(); 
    /*and in the methodcall sd[i].getmodel() it keeps telling that
      the symbol cannot be found but i'm sure that the method exists*/
  
   pr.println(model);}
  
  for(int j=0;j&lt;numOfComputerGames;j++){
  
  pr.println(cg[j].getname());} 
   /*i keep getting the same problem with cg[j].getname() */
  }
  catch(FileNotFoundException e){System.out.print(e.getMessage());}
  }}
  </code></pre>