public function save($file = null, $format = null, $formatted_xml = false)
    {
        $file = $file ? $file : $this->file;
        $format = $format ? $format : $this->format;
        if ($format == self::FORMAT_AUTO) {
            $format = $this->detectedFormat;
        }

        if (!in_array($format, array( self::FORMAT_BINARY, self::FORMAT_XML ))) {
            throw new PListException("format {$format} is not supported, use CFPropertyList::FORMAT_BINARY or CFPropertyList::FORMAT_XML");
        }

        if (!file_exists($file)) {
          // dirname("file.xml") == "" and is treated as the current working directory
            if (!is_writable(dirname($file))) {
                throw IOException::notWritable($file);
            }
        } elseif (!is_writable($file)) {
            throw IOException::notWritable($file);
        }

        $content = $format == self::FORMAT_BINARY ? $this->toBinary() : $this->toXML($formatted_xml);

        $fh = fopen($file, 'wb');
        fwrite($fh, $content);
        fclose($fh);
    }