File download URL Connection Desktop Application

Need to download files over API/webservice.
I checked the sample application in Example Projects? ? ?Communication? ? ?Internet? ? ?URLConnection ? FileDownloader.
This works great but in the path to download the files, the suffix is missed, so after download, the file is recognized as textfile.
I know the mimetype of the file. How can I set it to let the file have the correct filetype and maybe even the suffix after download?