quarta-feira, 28 de julho de 2010

[javautils] writeFile

   /**
    * Escreve um texto no arquivo (sobrescrevendo todo o texto que já existia nele)
    *
    * @param filename
    * @param texto
    */
   public static void writeFile(String filename, String texto) {
      try {
         FileWriter writer = new FileWriter(filename);
         BufferedWriter out = new BufferedWriter(writer);
         out.write(texto);
         out.close();
         writer.close();
      } catch (Throwable e) {
         throw new RuntimeException(
                  "JavaUtils.writeFile(String, String) - Erro desconhecido ao escrever um texto no arquivo \"" +
                           filename + "\". Error: " + e);
      }
   }  

Nenhum comentário: