Vala. Getting Content Type of a File

This Vala snippet shows how to get the content type of a file.

File file = File.new_for_path("Hello_World.txt");
try {
    string file_content_type = file.query_info ("*", FileQueryInfoFlags.NONE).get_content_type();
    stdout.printf ("Content type: %s\n", file_content_type);
} catch (Error e) {
    stdout.printf("Error occurred");
}

Result:

Content type: txt/plain