Example usage for java.io File createTempFile

List of usage examples for java.io File createTempFile

Introduction

In this page you can find the example usage for java.io File createTempFile.

Prototype

public static File createTempFile(String prefix, String suffix) throws IOException 

Source Link

Document

Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its name.

Usage

From source file:MainClass.java

public static void main(String[] a) throws Exception {
    File tmp = File.createTempFile("foo", "tmp");
    System.out.println("Your temp file is " + tmp.getCanonicalPath());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File f = File.createTempFile("temp_", null);

    System.out.println(f.getAbsolutePath());

    f.deleteOnExit();//w  w w  .ja  v a 2 s .c  o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    File f = File.createTempFile("tmp", ".txt");

    System.out.println("File path: " + f.getAbsolutePath());

    // deletes file when the virtual machine terminate
    f.deleteOnExit();/* w w  w .  j  a  v a2  s.c  o m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {

    File f = File.createTempFile("tmp", ".txt");

    System.out.println("File path: " + f.getAbsolutePath());

    // creates temporary file
    f = File.createTempFile("tmp", null);

    System.out.print("File path: " + f.getAbsolutePath());
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File file1 = null;//  www  .j  a v a  2 s  .c  o m
    File file2 = null;
    file1 = File.createTempFile("JavaTemp", null);
    file2 = File.createTempFile("JavaTemp", ".java");

    System.out.println(file1.getPath());
    System.out.println(file2.getPath());
}

From source file:Main.java

License:asdf

public static void main(String[] argv) throws Exception {
    File temp = File.createTempFile("pattern", ".dat");

    temp.deleteOnExit();//from   w w  w.  j a  v a 2  s. c  om

    BufferedWriter out = new BufferedWriter(new FileWriter(temp));
    out.write("asdf");
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) {
    try {//from   w ww .  j  a v  a 2 s. co  m
        File tempFile = File.createTempFile("myfile", ".tmp");
        FileOutputStream fout = new FileOutputStream(tempFile);
        PrintStream out = new PrintStream(fout);
        out.println("some text");
    } catch (IOException ex) {
        System.out.println("There was a problem creating/writing to the temp file");
        ex.printStackTrace();
    }
}

From source file:com.momab.dstool.IntegrationTest_Download.java

public static void main(String[] a) throws ParseException, IOException, ClassNotFoundException {

    File tmpFile = File.createTempFile("dstool", "dat");

    String[] args = { "localhost", "FeedItem", "-r", "-f", tmpFile.getAbsolutePath(), "-u", "user@domain", "-p",
            "password", "-P", "8888" };

    DSTool.main(args);//from  w  ww .ja  v a 2s.  c  om
}

From source file:base64test.Base64Test.java

/**
 * @param args the command line arguments
 *///  w  ww  .j a va 2 s .  c o  m
public static void main(String[] args) {
    try {
        if (!Base64.isBase64(args[0])) {
            throw new Exception("Arg 1 is not a Base64 string!");
        } else {
            String decodedBase64String = new String(Base64.decodeBase64(args[0]));
            File tempFile = File.createTempFile("base64Test", ".tmp");
            tempFile.deleteOnExit();
            FileWriter fw = new FileWriter(tempFile, false);
            PrintWriter pw = new PrintWriter(fw);
            pw.write(decodedBase64String);
            pw.close();
            String fileType = getFileType(tempFile.toPath());
            System.out.println(fileType);
            System.in.read();
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
}

From source file:edu.nju.cs.inform.jgit.CreateNewRepository.java

public static void main(String[] args) throws IOException, IllegalStateException, GitAPIException {
    // prepare a new folder
    File localPath = File.createTempFile("TestGitRepository", "");
    localPath.delete();//from   w w  w  .  j  av  a2  s  .c om

    // create the directory
    try (Git git = Git.init().setDirectory(localPath).call()) {
        System.out.println("Having repository: " + git.getRepository().getDirectory());
    }

    FileUtils.deleteDirectory(localPath);
}