FileSerialization.java 文件源码

java
阅读 26 收藏 0 点赞 0 评论 0

项目:SwornAPI 作者:
/**
 * Saves a serializable object to a given file.
 * 
 * @param instance Object to seriaize
 * @param file File to save to
 * @throws IllegalArgumentException If the instance or file is null
 * @throws IOException If the file cannot be written to
 * @see #load(File, Class, boolean)
 */
public static void save(ConfigurationSerializable instance, File file) throws IOException
{
    Validate.notNull(instance, "instance cannot be null!");
    Validate.notNull(file, "file cannot be null!");

    file.delete();
    file.createNewFile();

    YamlConfiguration config = new YamlConfiguration();

    for (Entry<String, Object> entry : instance.serialize().entrySet())
    {
        config.set(entry.getKey(), entry.getValue());
    }

    config.save(file);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号