You can do yes take the file without extension and convert to one with the desired extension.
public static void main(String[] args) throws IOException {
        String path = "C:\\Files\\Foto";
        byte[] imageInByte;
        BufferedImage originalImage = ImageIO.read(new File(
                path));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        String contentType = new Tika().detect(baos.toByteArray());
        ImageIO.write(originalImage, contentType, baos);
        baos.flush();
        imageInByte = baos.toByteArray();
        baos.close();
        InputStream in = new ByteArrayInputStream(imageInByte);
        BufferedImage bImageFromConvert = ImageIO.read(in);
        ImageIO.write(bImageFromConvert, contentType, new File(
                "C:\\Files\\Foto));
    }
Use that lib to detect the file type: https://www.apache.org/dyn/closer.cgi, lower and put on your classpath.
							
							
						 
Let’s say my file name is in "C: Photo Files", where photo is without its extension so it generates an Exception saying that the file does not exist.
– Fred
Qual Exception ?
– LR10
I TESTED IT RIGHT HERE!!
– LR10