javax.activation


1. Get MIME Type for a File

import javax.activation.*;

public class GetMimeType {

    public static void main(String[] args) {
        try {
            // Create an ActivationDataFlavor with the file's MIME type
            ActivationDataFlavor flavor = new ActivationDataFlavor(MimetypesFileTypeMap.getDefaultFileTypeMap());

            // Get the file's MIME type from the data flavor
            String mimeType = flavor.getMimeType();

            System.out.println("MIME type: " + mimeType);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2. Get MIME Type for a File Extension

3. Set MIME Type for a File

4. Create a MimeMultipart

5. Add an Attachment to a MimeMultipart

6. Get Attachment From MimeMultipart

7. Get Content-Type of a MimeMessage

8. Set Content-Type of a MimeMessage

9. Get Content-Disposition of a MimeBodyPart

10. Set Content-Disposition of a MimeBodyPart

11. Create a DataHandler

12. Get Content-Type of a DataHandler

13. Get Data Source from a DataHandler

14. Create a FileDataSource

15. Get Content-Type of a FileDataSource