さて、ダウンロードしたシートと一緒に「MyStore.obj」というファイルが添付されていました。そして、内容の順序で与えられたこのファイルの内容を読むことになっています.どうすればそれが存在するかどうかを確認できますか? ご覧のとおり、exists()メソッドを使用しようとしましたが、機能しませんでした
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<numOfStorageDevice;n++)
sd[n]=(StorageDevice)ois.readObject();
ComputerGame []cg=new ComputerGame[numOfComputerGames];
for(int m=0;m<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<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<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());}
}}