Hello I am having trouble reading a file in Java into a bytearray. Can someone help me with properly reading the file as I am getting errors including “The system cannot find the file specified” thought I have saved the file in the src folder.
Share
If you don’t provide a full path, the filename you specify will be relative to the working directory of your program.
It is therefore dependent on how you launch your code. Either use an absolute path, or put the file in the correct directory.
Typically if the file you want to read is to be distributed with your code, you instead want to use Java’s resource capabilities instead of interacting with the filesystem by putting the file in the classpath and loading it with
ClassLoader.getResource().