Discover the format of files without extension

1

I have thousands of photos on my computer but without the extension.

Because the extension has been deleted, I would like some Java library to manipulate those files / photos that are without extension and then discover its format in order to be able to rename. Since there are thousands of photos, checking one by one will take a long time. And as I like Java, it will be a lot of learning as well.

    
asked by anonymous 23.01.2018 / 04:48

2 answers

0

You can call Trid through a system command from within Java. It already has the option of already renaming the files to you by adding the extension.

Note that Trid has one executable for each operating system, so you will have to have a logic for each system you are supporting.

    
23.01.2018 / 05:10
0

You can do this to get the file without extension and convert it 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 this lib to detect the file type: link , low puts it in your classpath.

    
23.01.2018 / 13:26