MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / copyFile

Method copyFile

ij/src/main/java/ij/util/Tools.java:374–398  ·  view source on GitHub ↗

Copies the contents of the file at 'path1' to 'path2', returning an error message (as a non-empty string) if there is an error. Based on the method with the same name in Tobias Pietzsch's TifBenchmark class.

(String path1, String path2)

Source from the content-addressed store, hash-verified

372 same name in Tobias Pietzsch's TifBenchmark class.
373 */
374 public static String copyFile(String path1, String path2) {
375 File f1 = new File(path1);
376 File f2 = new File(path2);
377 try {
378 if (!f1.exists() )
379 return "Source file does not exist";
380 if (!f2.exists() )
381 f2.createNewFile();
382 long time = f1.lastModified();
383 FileInputStream stream1 = new FileInputStream(f1);
384 FileChannel channel1 = stream1.getChannel();
385 FileOutputStream stream2 = new FileOutputStream(f2);
386 final FileChannel channel2 = stream2.getChannel();
387 if (channel2!=null && channel1!=null )
388 channel2.transferFrom(channel1, 0, channel1.size());
389 channel1.close();
390 stream1.close();
391 channel2.close();
392 stream2.close();
393 f2.setLastModified(time);
394 } catch(Exception e) {
395 return e.getMessage();
396 }
397 return "";
398 }
399
400 /** Retrieves a number form a list of key-number pairs like "value1=1234.5 area=1.2e6".
401 * The "=" (if present) must be part of the 'key' string. Delimiters may be commas, semicolons or whitespace.

Callers 2

doFileMethod · 0.95
copyFileMethod · 0.95

Calls 5

getChannelMethod · 0.65
closeMethod · 0.65
existsMethod · 0.45
sizeMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected