Sample code for 30+ languages & platforms
Java Requires Chilkat v11.0.0+

Extract Files from MIME

See more MIME Examples

Extract files from a MIME message.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Mime;
import com.chilkatsoft.chilkat2.StringTable;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Mime mime = new Mime();

        // Load a MIME document from a file:
        // (.mht and .eml files contain MIME).
        try {
            mime.loadMimeFile("mst.mht");
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        StringTable st = new StringTable();
        try {
            mime.partsToFiles("/temp/mimeParts", st);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        int n = st.getCount();

        // Display the paths of the files created:
        int i = 0;
        while (i < n) {
            System.out.println(st.stringAt(i));
            i = i + 1;
        }
    }
}