was initially using jfilechooser to upload jpg files into project but switched to jFileDialog because I wanted to get the images in thumbnail view. but when I run the project, I get this error msg:
javax.imageio.IIOException:Cant read input file!
this is the code below:
FileDialog fd = new FileDialog(this,"Choose a File",FileDialog.LOAD);
fd.setDirectory("C:\\");
fd.setFile("*.jpg;*.jpeg");
fd.setVisible(true);
filename = fd.getFile();
if(filename==null){
}else{
try{
File imgs =new File(filename);
BufferedImage bufferedimage=ImageIO.read(imgs);
BufferedImage thumbnail=Thumbnails.of(bufferedimage)
.size(145, 141)
.asBufferedImage();
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(thumbnail,"jpeg", os);
InputStream is=new ByteArrayInputStream(os.toByteArray());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf =new byte[1024];
try{
for(int readNum; (readNum=is.read(buf))!=-1;){
bos.write(buf,0,readNum);
System.out.println("Read" +readNum+ "bytes,");
}
}catch(IOException ex){
Logger.getLogger(null);
}
person_image=bos.toByteArray();
}catch(Exception e){
JOptionPane.showMessageDialog(null, e);
}finally{
try{
rs.close();
pst.close();
}
catch(Exception e){
}
}
I think the problem is coming from this section:
File imgs =new File(filename);
BufferedImage bufferedimage=ImageIO.read(imgs);
it doesn't seem to get the file. please what am I doing wrong?