Here you can find the source of createTemporaryFileFromURL(final URL url)
Parameter | Description |
---|---|
url | the URL to read from. |
public static File createTemporaryFileFromURL(final URL url)
//package com.java2s; /**/*www .ja v a 2 s.c om*/ * Copyright 2014 VU University Medical Center. * Licensed under the Apache License version 2.0 (see http://www.apache.org/licenses/LICENSE-2.0.html). */ import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.file.Files; import java.nio.file.StandardCopyOption; public class Main { /** * File name prefix for files that are created. */ private static final String FILE_NAME_PREFIX = "workflow-runner"; /** * File name suffix for files that are created. */ private static final String FILE_NAME_SUFFIX = ".txt"; /** * Create a temporary file from the contents of a URL. * * @param url the URL to read from. * @return the test file. */ public static File createTemporaryFileFromURL(final URL 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; } }