当前位置: 首页>>代码示例>>Java>>正文


Java Files.move方法代码示例

本文整理汇总了Java中java.nio.file.Files.move方法的典型用法代码示例。如果您正苦于以下问题:Java Files.move方法的具体用法?Java Files.move怎么用?Java Files.move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.move方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTransactionOutput

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public OutputStream createTransactionOutput() throws IOException {
    Path tmpFile = m_transactionTmpDir.resolve(getFileName(m_tmpCounter.getAndIncrement(), TX_EXT));

    return new BufferedOutputStream(Files.newOutputStream(tmpFile)) {
        @Override
        public void close() throws IOException {
            super.close();
            synchronized (m_commitLock) {
                long transactionId = m_nextTxId++;
                Path txFile = getTxFile(transactionId);

                Files.move(tmpFile, txFile);
                m_commitLock.notifyAll();
            }
        }
    };
}
 
开发者ID:Axway,项目名称:iron,代码行数:19,代码来源:FileTransactionStore.java

示例2: rename

import java.nio.file.Files; //导入方法依赖的package包/类
@Override public Resource rename(String text) {
    try {
        File sourceFile = path.toFile();
        File destinationFile = path.resolveSibling(text).toFile();
        Path moved;
        if (!sourceFile.getParent().equals(destinationFile.getParent())) {
            moved = Files.move(path, path.resolveSibling(text));
        } else {
            sourceFile.renameTo(destinationFile);
            moved = destinationFile.toPath();
        }
        FileResource to = new FileResource(moved.toFile());
        Event.fireEvent(this, new ResourceModificationEvent(ResourceModificationEvent.MOVED, this, to));
        return to;
    } catch (IOException e) {
        FXUIUtils.showMessageDialog(null, "Unable to rename file: " + e.getMessage(), e.getClass().getName(), AlertType.ERROR);
        return null;
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:20,代码来源:FileResource.java

示例3: renameFile

import java.nio.file.Files; //导入方法依赖的package包/类
public static Boolean renameFile(String fromFile, String toName) {
    try {
        File src = new File(fromFile);
        if (src.exists()) {
            File target = new File(src.getParent(), toName);
            if (target.exists()) {
                LOGGER.log(Level.INFO, "A File with Name '{1}' already exists, failed to rename '{0}'",
                        new Object[]{fromFile, toName});
                return false;
            }
            Files.move(src.toPath(), target.toPath());
        }
    } catch (IOException ex) {
        Logger.getLogger(FileUtils.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    }
    LOGGER.log(Level.INFO, "{0} Renamed to {1}", new Object[]{fromFile, toName});
    return true;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:20,代码来源:FileUtils.java

示例4: create

import java.nio.file.Files; //导入方法依赖的package包/类
private boolean create() throws IOException {
    JmodFileWriter jmod = new JmodFileWriter();

    // create jmod with temporary name to avoid it being examined
    // when scanning the module path
    Path target = options.jmodFile;
    Path tempTarget = jmodTempFilePath(target);
    try {
        try (JmodOutputStream jos = JmodOutputStream.newOutputStream(tempTarget)) {
            jmod.write(jos);
        }
        Files.move(tempTarget, target);
    } catch (Exception e) {
        try {
            Files.deleteIfExists(tempTarget);
        } catch (IOException ioe) {
            e.addSuppressed(ioe);
        }
        throw e;
    }
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:JmodTask.java

示例5: z2zmove

import java.nio.file.Files; //导入方法依赖的package包/类
private static void z2zmove(FileSystem src, FileSystem dst, String path)
    throws IOException
{
    Path srcPath = src.getPath(path);
    Path dstPath = dst.getPath(path);

    if (Files.isDirectory(srcPath)) {
        if (!Files.exists(dstPath))
            mkdirs(dstPath);
        try (DirectoryStream<Path> ds = Files.newDirectoryStream(srcPath)) {
            for (Path child : ds) {
                z2zmove(src, dst,
                        path + (path.endsWith("/")?"":"/") + child.getFileName());
            }
        }
    } else {
        //System.out.println("moving..." + path);
        Path parent = dstPath.getParent();
        if (parent != null && Files.notExists(parent))
            mkdirs(parent);
        Files.move(srcPath, dstPath);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:ZipFSTester.java

示例6: update

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void update(Session session) {
    final String sessionId = ensureStringSessionId(session);
    final Path oldPath = sessionId2Path(sessionId);
    if (!Files.exists(oldPath)) {
        throw new UnknownSessionException(sessionId);
    }

    try {
        final Path newPath = Files.createTempFile(tmpDir, null, null);
        Files.write(newPath, serialize(session));
        Files.move(newPath, oldPath, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        throw new SerializationException(e);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:17,代码来源:FileBasedSessionDAO.java

示例7: generateJAXPProps

import java.nio.file.Files; //导入方法依赖的package包/类
static void generateJAXPProps(String content) throws IOException {
    Path filePath = getJAXPPropsPath();
    Path bakPath = filePath.resolveSibling(JAXP_PROPS_BAK);
    System.out.println("Creating new file " + filePath +
        ", saving old version to " + bakPath + ".");
    if (Files.exists(filePath) && !Files.exists(bakPath)) {
        Files.move(filePath, bakPath);
    }

    Files.write(filePath, content.getBytes());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:CatalogTestUtils.java

示例8: update

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void update(File updateFile, Plugin plugin) throws IOException {
    Path src = updateFile.toPath();
    Path trg = UpdateMethod.getPluginFile(plugin).toPath();
    try {
        Files.move(src, trg, ATOMIC_MOVE);
    } catch (Exception e) {
        //Fallback
        Files.move(src, trg, REPLACE_EXISTING);
    }
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:12,代码来源:ReplaceUpdateMethod.java

示例9: close

import java.nio.file.Files; //导入方法依赖的package包/类
@Override
public void close() throws IOException {
    if (!closed) {
        // close new entry
        os.closeEntry();

        // copy existing entries
        if (Files.exists(zipFilePath)) {
            try (ZipFile zipFile = new ZipFile(zipFilePath)) {
                Enumeration<? extends ZipEntry> e = zipFile.entries();
                while (e.hasMoreElements()) {
                    ZipEntry zipEntry = e.nextElement();
                    if (!zipEntry.getName().equals(fileName)) {
                        os.putNextEntry(zipEntry);
                        try (InputStream zis = zipFile.getInputStream(zipEntry.getName())) {
                            ByteStreams.copy(zis, os);
                        }
                        os.closeEntry();
                    }
                }
            }
        }

        // close zip
        super.close();

        // swap with tmp zip
        Path tmpZipFilePath = getTmpZipFilePath(zipFilePath);
        Files.move(tmpZipFilePath, zipFilePath, StandardCopyOption.REPLACE_EXISTING);

        closed = true;
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:34,代码来源:ZipFileDataSource.java

示例10: renameFile

import java.nio.file.Files; //导入方法依赖的package包/类
@SneakyThrows(IOException.class)
private void renameFile() {
    Path path = places.closeAndGetRenameFolderPlace();
    String nameOfFolder = name.getText();
    Path pathRename = path.getParent().resolve(nameOfFolder);
    Files.move(path, pathRename);
}
 
开发者ID:MrChebik,项目名称:Coconut-IDE,代码行数:8,代码来源:RenameFolderPresenter.java

示例11: main

import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) {
    Path src = Paths.get(System.getProperty("user.home") + "myfile.txt");
    Path dest = Paths.get(System.getProperty("user.home") + "/test/myfile.txt");

    try {
        // 如果目标文件存在则先删除,防止干扰move的结果
        Files.delete(dest);
        Files.move(src, dest, REPLACE_EXISTING); // |\longremark{可以尝试去掉REPLACE\_EXISTING参数看看运行结果有什么不同?}|
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println("move file success? " + Files.exists(dest));
}
 
开发者ID:subaochen,项目名称:java-tutorial,代码行数:15,代码来源:PathMoveTest.java

示例12: moveFilesDirs

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Move files (or directories) to specified path
 * @param originPath String that contains the original file/folder to be moved
 * @param destinationPath String that contains the destination path to save the old file/directories
 * @param replaceExisting boolean that indicates if replace any existing file/directory if duplicated
 */
public static void moveFilesDirs(String originPath, String destinationPath, boolean replaceExisting) {
    try {
        if (replaceExisting)
            Files.move(Paths.get(originPath), Paths.get(destinationPath), REPLACE_EXISTING);
        else
            Files.move(Paths.get(originPath), Paths.get(destinationPath));
    } catch (IOException e) {
        IO.write("There was an error while trying to move the file/dir specified. Full trace: \n");
        e.printStackTrace();
    }
}
 
开发者ID:Javinator9889,项目名称:IOManager,代码行数:18,代码来源:IOManager.java

示例13: movefile

import java.nio.file.Files; //导入方法依赖的package包/类
static void movefile(String f) throws IOException {
    Path src = Paths.get(testclasses, f);
    Path dest = subdir.toPath().resolve(f);
    if (!dest.toFile().exists()) {
        System.out.printf("moving %s to %s\n", src.toString(), dest.toString());
        Files.move(src, dest,  StandardCopyOption.REPLACE_EXISTING);
    } else if (src.toFile().exists()) {
        System.out.printf("%s exists, deleting %s\n", dest.toString(), src.toString());
        Files.delete(src);
    } else {
        System.out.printf("NOT moving %s to %s\n", src.toString(), dest.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:Security.java

示例14: setup

import java.nio.file.Files; //导入方法依赖的package包/类
@BeforeTest
private void setup() throws Exception {
    Files.createDirectory(BAR_DIR);

    Path pkgDir = Paths.get("p");
    // compile classes in package p
    assertTrue(CompilerUtils.compile(SRC_DIR.resolve(pkgDir), BAR_DIR));

    // move p.Foo to a different directory
    Path foo = pkgDir.resolve("Foo.class");
    Files.createDirectories(FOO_DIR.resolve(pkgDir));
    Files.move(BAR_DIR.resolve(foo), FOO_DIR.resolve(foo),
               StandardCopyOption.REPLACE_EXISTING);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:SplitPackage.java

示例15: writeLayer

import java.nio.file.Files; //导入方法依赖的package包/类
public CachedLayer writeLayer(UnwrittenLayer layer) throws IOException {
  // Writes to a temporary file first because the UnwrittenLayer needs to be written first to
  // obtain its digest.
  Path tempLayerFile = Files.createTempFile(cache.getCacheDirectory(), null, null);
  // TODO: Find a way to do this with java.nio.file
  tempLayerFile.toFile().deleteOnExit();

  // Writes the UnwrittenLayer layer BLOB to a file to convert into a CachedLayer.
  try (CountingDigestOutputStream compressedDigestOutputStream =
      new CountingDigestOutputStream(
          new BufferedOutputStream(Files.newOutputStream(tempLayerFile)))) {
    // Writes the layer with GZIP compression. The original bytes are captured as the layer's
    // diff ID and the bytes outputted from the GZIP compression are captured as the layer's
    // content descriptor.
    GZIPOutputStream compressorStream = new GZIPOutputStream(compressedDigestOutputStream);
    DescriptorDigest diffId = layer.getBlob().writeTo(compressorStream).getDigest();

    // The GZIPOutputStream must be closed in order to write out the remaining compressed data.
    compressorStream.close();
    BlobDescriptor compressedBlobDescriptor = compressedDigestOutputStream.toBlobDescriptor();

    // Renames the temporary layer file to the correct filename.
    Path layerFile =
        CacheFiles.getLayerFile(cache.getCacheDirectory(), compressedBlobDescriptor.getDigest());
    // TODO: Should probably check for existence of target file and whether or not it's the same.
    try {
      Files.move(tempLayerFile, layerFile);

    } catch (IOException ex) {
      throw new IOException(
          "Could not rename layer "
              + compressedBlobDescriptor.getDigest().getHash()
              + " to "
              + layerFile,
          ex);
    }

    return new CachedLayer(layerFile, compressedBlobDescriptor, diffId);
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:minikube-build-tools-for-java,代码行数:41,代码来源:CacheWriter.java


注:本文中的java.nio.file.Files.move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。