< prev index next >

src/java.base/share/classes/java/nio/file/Files.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1374      * </pre>
1375      *
1376      * @param   source
1377      *          the path to the file to move
1378      * @param   target
1379      *          the path to the target file (may be associated with a different
1380      *          provider to the source path)
1381      * @param   options
1382      *          options specifying how the move should be done
1383      *
1384      * @return  the path to the target file
1385      *
1386      * @throws  UnsupportedOperationException
1387      *          if the array contains a copy option that is not supported
1388      * @throws  FileAlreadyExistsException
1389      *          if the target file exists but cannot be replaced because the
1390      *          {@code REPLACE_EXISTING} option is not specified <i>(optional
1391      *          specific exception)</i>
1392      * @throws  DirectoryNotEmptyException
1393      *          the {@code REPLACE_EXISTING} option is specified but the file
1394      *          cannot be replaced because it is a non-empty directory
1395      *          <i>(optional specific exception)</i>

1396      * @throws  AtomicMoveNotSupportedException
1397      *          if the options array contains the {@code ATOMIC_MOVE} option but
1398      *          the file cannot be moved as an atomic file system operation.
1399      * @throws  IOException
1400      *          if an I/O error occurs
1401      * @throws  SecurityException
1402      *          In the case of the default provider, and a security manager is
1403      *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
1404      *          method is invoked to check write access to both the source and
1405      *          target file.
1406      */
1407     public static Path move(Path source, Path target, CopyOption... options)
1408         throws IOException
1409     {
1410         FileSystemProvider provider = provider(source);
1411         if (provider(target) == provider) {
1412             // same provider
1413             provider.move(source, target, options);
1414         } else {
1415             // different providers


   1 /*
   2  * Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


1374      * </pre>
1375      *
1376      * @param   source
1377      *          the path to the file to move
1378      * @param   target
1379      *          the path to the target file (may be associated with a different
1380      *          provider to the source path)
1381      * @param   options
1382      *          options specifying how the move should be done
1383      *
1384      * @return  the path to the target file
1385      *
1386      * @throws  UnsupportedOperationException
1387      *          if the array contains a copy option that is not supported
1388      * @throws  FileAlreadyExistsException
1389      *          if the target file exists but cannot be replaced because the
1390      *          {@code REPLACE_EXISTING} option is not specified <i>(optional
1391      *          specific exception)</i>
1392      * @throws  DirectoryNotEmptyException
1393      *          the {@code REPLACE_EXISTING} option is specified but the file
1394      *          cannot be replaced because it is a non-empty directory, or the
1395      *          source is a non-empty directory containing entries that would
1396      *          be required to be moved <i>(optional specific exceptions)</i>
1397      * @throws  AtomicMoveNotSupportedException
1398      *          if the options array contains the {@code ATOMIC_MOVE} option but
1399      *          the file cannot be moved as an atomic file system operation.
1400      * @throws  IOException
1401      *          if an I/O error occurs
1402      * @throws  SecurityException
1403      *          In the case of the default provider, and a security manager is
1404      *          installed, the {@link SecurityManager#checkWrite(String) checkWrite}
1405      *          method is invoked to check write access to both the source and
1406      *          target file.
1407      */
1408     public static Path move(Path source, Path target, CopyOption... options)
1409         throws IOException
1410     {
1411         FileSystemProvider provider = provider(source);
1412         if (provider(target) == provider) {
1413             // same provider
1414             provider.move(source, target, options);
1415         } else {
1416             // different providers


< prev index next >