Read file located in another Package

2

Ihave3packages,onewheretheguiclassislocated,anotherwhereitwillbethe"scripts" of reading data (in main) and photos and text files in the resources.

    File file = new File("/com/Convocatoria/resources/DB.txt");
    Scanner sc = new Scanner(file);

I will use the scanner to read the file however it gives me the error

  

Unhandled exception type FileNotFoundException

    
asked by anonymous 02.06.2018 / 11:29

1 answer

4

The error is caused by the packet hierarchy reported as path in the class. For print, there is no "with" package or no package with this in the name, so this path entered is non-existent in the project.

You should enter the path to the file, always following its package hierarchy, in which case only /Convocatoria/resources/DB.txt would suffice:

File file = new File("/Convocatoria/resources/DB.txt");
Scanner sc = new Scanner(file);

There is no obligation to inform with in java, this is just a convention inherited from the android, to organize the hierarchy, but if you do not follow, you do not have to use the path of some file.

    
02.06.2018 / 15:23