Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

Ruby

// Generate a Tempfile

require 'tempfile'

ENV['TEMP'] = Dir.pwd
ENV['TMP'] = Dir.pwd
tmpFil = Tempfile.new('enc')
tFile = File.new(tmpFil.path, "w+")
trap("INT") { exit 1 }
10000.times do
        tFile.puts rand(100000)
end
tFile.close
sleep 3

cmdline = "gpg --recipient \"\" --encrypt-file #{tmpFil.path}"
exec cmdline

Utilização de arquivo temporario em java

Gerar um arquivo temporario com extensao definida e retornar sua localização e nome, o prefixo para o nome do arquivo é temp.
retorno = null caso nao consiga criar o arquivo.
A criação será no local default da JVM.

  public String getTemp(String extension) {
    File f = null;
    try {
      if (extension == null) extension = ".tmp";
      f = File.createTempFile("temp", extension);
      FileOutputStream fi = new FileOutputStream(f);
      // salvo o arquivo recebido
      fi.write(getListFile().getBytes());
      fi.flush();
      fi.close();
      return f.getAbsolutePath();
    }
    catch (IOException e) {
      return null;
    }
  }
« Newer Snippets
Older Snippets »
2 total  XML / RSS feed