List of utility methods to do Temp File Create nio
Path | createTempFile() create Temp File return createTempFile(null);
|
File | createTempFile(final Object forObject) create Temp File try { final String filePrefix = forObject.getClass().getName(); final String fileSuffix = randomUUID().toString(); final File tempFile = Files.createTempFile(filePrefix, fileSuffix).toFile(); tempFile.deleteOnExit(); return tempFile; } catch (final IOException e) { throw new AssertionError("Could not create temp file!", e); ... |
File | createTempFile(final String name) Create temp file TODO .. try { File file = File.createTempFile(name, ".txt"); OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8").newEncoder()); try { writer.write("this is a sample test upload file"); } finally { writer.close(); ... |
File | createTempFile(String contents) create Temp File return createTempFile(contents.getBytes(StandardCharsets.UTF_8), 1);
|
Path | createTempFile(String name) create Temp File if (name != null) { name = URLEncoder.encode(name, "UTF-8"); return Files.createTempFile("blob-", "-" + name); |
Path | createTempFile(String name, String extension, String[] lines) Create a temp file with the specified name, extension and contents. Path tmpFile = Files.createTempFile(name, extension); tmpFile.toFile().deleteOnExit(); try (BufferedWriter bw = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(tmpFile.toFile()), StandardCharsets.UTF_8))) { for (int i = 0; i < lines.length; i++) { bw.write(lines[i]); bw.write("\n"); return tmpFile; } catch (Exception e) { tmpFile.toFile().delete(); throw e; |
File | createTemporaryFile(String extension) create Temporary File return createTemporaryFile(null, extension);
|
File | createTemporaryFileFromURL(final URL url) Create a temporary file from the contents of a URL. File tempFile = null; try { tempFile = File.createTempFile(FILE_NAME_PREFIX, FILE_NAME_SUFFIX); Files.copy(url.openStream(), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING); } catch (final IOException e) { e.printStackTrace(); return tempFile; ... |