Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you need to copy large files, or files and all the system permissions associated with a file, using java internal File.copy() will be too expensive, so you can offload all the load to your system.</p> <p>Try the following trick - first, user string array as an argument to exec(); second, execute your 'xcopy' in a pipe after 'cmd' command with /C argument. Look at the sample code near line where I make isWindows() call. </p> <p>The trick is that your xcopy command will be executed inside CMD shell, and /C will terminate it after successful execution. More about<a href="http://ss64.com/nt/cmd.html" rel="nofollow">CMD.exe</a>.</p> <pre><code>public int sysCopyFile(Resource fromResource, Resource toResource) throws ServiceException { int returnCode = -1; try { String[] copyCommand = null; if ( IOUtils.isWindows() ) { copyCommand = new String[] {"cmd", "/C", "copy", "/Y", fromResource.getFile().getAbsolutePath(), toResource.getFile().getAbsolutePath()}; } else if ( IOUtils.isUnix() || IOUtils.isMac() ) { copyCommand = new String[] {"/bin/cp", "-pr", fromResource.getFile().getAbsolutePath(),toResource.getFile().getAbsolutePath()}; } final Process p = Runtime.getRuntime().exec(copyCommand); new StreamLogger(p.getErrorStream(), log, StreamLogger.WARN); new StreamLogger(p.getInputStream(), log, StreamLogger.DEBUG); returnCode = p.waitFor(); if (returnCode != 0) throw new ServiceException("Unable to to copy. Command: {" + copyCommand[0] + "} has returned non-zero returnCode: " + returnCode); } catch (IOException e) { throw new ServiceException(e); } catch (InterruptedException e) { throw new ServiceException(e); } return returnCode; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload