/** * Creates a {@link Writer} for writing content to the file use default charset {@link Charsets#defaultCharset()} * * <p> * Note : * <strong> * You must close the retured {@link Writer}. * </strong> * * @throws NestedIOException if an I/O error occurs. */ public static Writer createWriter(File file) throws NestedIOException { return createWriter(file,Charsets.defaultCharset()); }
/** * Saving the given {@link Properties} to the given file use default charset {@link Charsets#defaultCharset()}. * * @throws NestedIOException if an I/O error occurs. */ public static void save(Properties props, File file) throws NestedIOException { Args.notNull(props,"properties"); Args.notNull(file,"file"); try{ if(!file.exists()){ file.createNewFile(); } if(Strings.endsWithIgnoreCase(file.getName(), ".xml")){ try(OutputStream out = new FileOutputStream(file)){ props.storeToXML(out, ""); } }else{ try(Writer writer = IO.createWriter(file)){ props.store(writer, ""); } } }catch(IOException e){ throw new NestedIOException("Error saving properties file '" + file.getAbsolutePath() + "', " + e.getMessage(), e); } }