Changeset 7003 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2014-04-26T14:30:11+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6999 r7003 17 17 import java.io.Closeable; 18 18 import java.io.File; 19 import java.io.FileInputStream;20 import java.io.FileOutputStream;21 19 import java.io.IOException; 22 20 import java.io.InputStream; … … 29 27 import java.net.URLConnection; 30 28 import java.net.URLEncoder; 31 import java.nio.channels.FileChannel;32 29 import java.nio.charset.Charset; 30 import java.nio.file.Files; 31 import java.nio.file.Path; 32 import java.nio.file.StandardCopyOption; 33 33 import java.security.MessageDigest; 34 34 import java.security.NoSuchAlgorithmException; … … 323 323 /** 324 324 * Simple file copy function that will overwrite the target file.<br> 325 * Taken from <a href="http://www.rgagnon.com/javadetails/java-0064.html">this article</a> (CC-NC-BY-SA)326 325 * @param in The source file 327 326 * @param out The destination file 327 * @return the path to the target file 328 328 * @throws java.io.IOException If any I/O error occurs 329 */ 330 public static void copyFile(File in, File out) throws IOException { 331 // TODO: remove this function when we move to Java 7 (use Files.copy instead) 332 FileInputStream inStream = null; 333 FileOutputStream outStream = null; 334 try { 335 inStream = new FileInputStream(in); 336 outStream = new FileOutputStream(out); 337 FileChannel inChannel = inStream.getChannel(); 338 inChannel.transferTo(0, inChannel.size(), outStream.getChannel()); 339 } 340 catch (IOException e) { 341 throw e; 342 } 343 finally { 344 close(outStream); 345 close(inStream); 346 } 329 * @throws IllegalArgumentException If {@code in} or {@code out} is {@code null} 330 * @since 7003 331 */ 332 public static Path copyFile(File in, File out) throws IOException, IllegalArgumentException { 333 CheckParameterUtil.ensureParameterNotNull(in, "in"); 334 CheckParameterUtil.ensureParameterNotNull(out, "out"); 335 return Files.copy(in.toPath(), out.toPath(), StandardCopyOption.REPLACE_EXISTING); 347 336 } 348 337
Note:
See TracChangeset
for help on using the changeset viewer.