私は以下のコードを持っています。
以下のソースコードは、ファイルx.javaからのものです。hi.htmlは、x.javaと同じディレクトリにあります。
ファイルが存在していても、ファイルが見つからないという例外が発生します。私は何かが足りないのですか?
public void sendStaticResource() throws IOException{
byte[] bytes = new byte[1024];
FileInputStream fis = null;
try{
File file = new File("hi.html");
boolean p = file.exists();
int i = fis.available();
fis = new FileInputStream(file);
int ch = fis.read(bytes, 0, 1024);
while(ch!=-1){
output.write(bytes, 0, ch);
ch = fis.read(bytes, 0, 1024);
}
}catch(Exception e){
String errorMessage = "file not found";
output.write(errorMessage.getBytes());
}finally {
if(fis != null){
fis.close();
}
}
}