java - FileNotFoundException in my class application -


java.io.filenotfoundexception: monsters.txt (the system cannot find file specified)     @ java.io.fileinputstream.open(native method)     @ java.io.fileinputstream.<init>(fileinputstream.java:138)     @ java.io.fileinputstream.<init>(fileinputstream.java:93)     @ java.io.filereader.<init>(filereader.java:58)  @ monsterapp.main(monsterapp.java:28) 

this error receiving while running application.. cant seem fix code. looking @ happen error.


this code app im running

__ public class monsterapp {

//a list of monsters read in. private static arraylist<monster> monsters = new arraylist<monster>();  /**  * main method  * @param args  */ public static void main(string[] args) {     //try ioexceptions -- called when file cannot found     try {         /* requirement : file input */         //connect monsters.txt file         bufferedreader br = new bufferedreader(new filereader("monsters.txt"));          string line = "";          //read in each line         while((line = br.readline()) != null) {             //split line             string[] parts = line.split(",");              //try create monsters file details             try {                 //swtich kind of monster                 switch(parts[0]) {                     case "chimera":                         /* requirement : polymorphism */                         //add chimera monster list                         monsters.add(new chimera(monster.size.indexof(parts[1]), integer.parseint(parts[2]), integer.parseint(parts[3]),                                  parts[4], integer.parseint(parts[5])));                         break;                     case "hydra":                         /* requirement : polymorphism */                         //add hydra monster list                         monsters.add(new hydra(monster.size.indexof(parts[1]), integer.parseint(parts[2]), integer.parseint(parts[3]),                                  parts[4], integer.parseint(parts[5]), new toy(parts[6], parts[7])));                         break;                 }             } catch (monsterexception ex) {                 //something wrong monster, output message                 system.out.println(ex.getmessage());             }         }          //loop through monsters         for(monster mon : monsters) {             //output tostring result of each monster             system.out.println(mon.tostring());              //call scare method             mon.scare();              //call sleep method             mon.sleep();         }          //close file         br.close();          //open runcount file         bufferedreader br2 = new bufferedreader(new filereader("runcount.txt"));          //read number of runs         int count = integer.parseint(br2.readline());          //close file         br2.close();          //get file         file file = new file("runcount.txt");          //open writing         printwriter pw = new printwriter(file);          //increment count         count++;          /* requirement : file output */         //output file         pw.println(count);          //close file         pw.close();          //output run count information         system.out.println("\nthis program has been run " + count + " times");     } catch (ioexception e) {         //a file reading/writing error has occurred.         e.printstacktrace();     }    } 

}

change code new filereader(name) new filereader(new file(name).getabsolutefile()) , exception tell tries find file. not place think is.


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -