The FileNotFoundException class appears to be missing from java.io?

I'm trying to code a simple server and client in Eclipse for a school assignment. At some point, I need to send a file from the client to the server, and wrote this:

File file = new File("./test.png");         
long length = file.length();
byte [] mybytearray  = new byte [(int)length];
FileInputStream fis;
fis = new FileInputStream(file);
                

Eclipse highlights the last line in red, telling me that "The constructor FileInputStream(File) refers to the missing type FileNotFoundException". After some research and testing, I'm pretty sure this is not a problem with the file itself. It exists, is readable, and is not a directory. I decide to include the class with

import java.io.FileNotFoundException;

which tells me "The import java.io.FileNotFoundException cannot be resolved". It looks to me like Eclipse thinks the class does not exist, but all my other java.io imports are working perfectly fine, and I never messed around in my libraries folder, so I have no idea what the source of the problem is. I already tried some common tips like cleaning my projects, but I have no idea where to go from here.

Like, if all my imports failed, then I'm clearly doing something wrong, but the fact it's only this one that's failing is bizarre.



Read more here: https://stackoverflow.com/questions/66345388/the-filenotfoundexception-class-appears-to-be-missing-from-java-io

Content Attribution

This content was originally published by Gabriel Bruno at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: