简体   繁体   中英

Eclipse unable to import File object FileNotFoundException

I am new for Importing file using scanner line by line reader .When i have import file it's working correctly , but some other system(ie colleague system) same project and same database connection while importing file error like Java.io.FileNotfoundException local drive fake path directory (eg: "c:\\fake path\\db.sql").

public boolean checkfile(String dbfile){
   File obj = new File(dbfile)
   Scanner scr = new Scanner(obj );
   try{
    while(scr .hasNext()){
     String scr_line = scr.nextLine();
     System.out.println(scr_line );
    }
   }catch(Exception ex){
    System.out.println(ex.tostring());
   }
 }

Above code File obj = new File(dbFile) this line error message showing like Java.io.FileNotFoundException local drive fake path directory . can any please help me where i have done mistake above this code .

1 , File you try read is not available in your colleague system or where you run this java program

2 , check this file "c:\\fake path\\db.sql" is available or not in where you run this java program

3 , When you run the program make sure you are sending the file path based on the Environment(Windows,unix etc.....)

4 , check File availability first

try
{
File f = new File("c:\fake path\db.sql");
if(f.exists())
   {
        //read the file
    }
}
catch(Exception e)
{
// do some work
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM