本文整理了Java中org.apache.commons.io.FileUtils.moveDirectoryToDirectory()
方法的一些代码示例,展示了FileUtils.moveDirectoryToDirectory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.moveDirectoryToDirectory()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:moveDirectoryToDirectory
[英]Moves a directory to another directory.
[中]将目录移动到另一个目录。
代码示例来源:origin: commons-io/commons-io
moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
moveFileToDirectory(src, destDir, createDestDir);
代码示例来源:origin: apache/kylin
FileUtils.moveDirectoryToDirectory(file, tempZipDir, false);
} else {
FileUtils.moveFileToDirectory(file, tempZipDir, false);
代码示例来源:origin: commons-io/commons-io
@Test
public void testIO300() throws Exception {
final File testDirectory = getTestDirectory();
final File src = new File(testDirectory, "dir1");
final File dest = new File(src, "dir2");
assertTrue(dest.mkdirs());
assertTrue(src.exists());
try {
FileUtils.moveDirectoryToDirectory(src, dest, false);
fail("expected IOException");
} catch (final IOException ioe) {
// expected
}
assertTrue(src.exists());
}
代码示例来源:origin: commons-io/commons-io
FileUtils.moveDirectoryToDirectory(src, destDir, true);
代码示例来源:origin: commons-io/commons-io
@Test
public void testMoveDirectoryToDirectory_Errors() throws Exception {
try {
FileUtils.moveDirectoryToDirectory(null, new File("foo"), true);
fail("Expected NullPointerException when source is null");
} catch (final NullPointerException e) {
FileUtils.moveDirectoryToDirectory(new File("foo"), null, true);
fail("Expected NullPointerException when destination is null");
} catch (final NullPointerException e) {
FileUtils.moveDirectoryToDirectory(testFile1, testFile2, true);
fail("Expected IOException when dest not a directory");
} catch (final IOException e) {
FileUtils.moveDirectoryToDirectory(testFile1, nonexistant, false);
fail("Expected IOException when dest does not exist and create=false");
} catch (final IOException e) {
代码示例来源:origin: commons-io/commons-io
@Test
public void testMoveToDirectory_Errors() throws Exception {
try {
FileUtils.moveDirectoryToDirectory(null, new File("foo"), true);
fail("Expected NullPointerException when source is null");
} catch (final NullPointerException e) {
// expected
}
try {
FileUtils.moveDirectoryToDirectory(new File("foo"), null, true);
fail("Expected NullPointerException when destination is null");
} catch (final NullPointerException e) {
// expected
}
final File nonexistant = new File(getTestDirectory(), "nonexistant");
final File destDir = new File(getTestDirectory(), "MoveToDirectoryDestDir");
try {
FileUtils.moveToDirectory(nonexistant, destDir, true);
fail("Expected IOException when source does not exist");
} catch (final IOException e) {
// expected
}
}
代码示例来源:origin: DaxiaK/MyDiary
public static boolean Version17MoveTheDiaryIntoNewDir(Context context) throws Exception {
FileManager rootFileManager = new FileManager(context, FileManager.ROOT_DIR);
File[] dataFiles = rootFileManager.getDir().listFiles();
boolean moveIntoNewDir = false;
//router all dir first
for (int i = 0; i < dataFiles.length; i++) {
if (FileManager.isNumeric(dataFiles[i].getName()) && dataFiles[i].listFiles().length > 0) {
moveIntoNewDir = true;
break;
}
}
//If the numeric dir is exist , move it
if (moveIntoNewDir) {
FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR);
File destDir = diaryFM.getDir();
FileUtils.deleteDirectory(destDir);
for (int i = 0; i < dataFiles.length; i++) {
if (FileManager.isNumeric(dataFiles[i].getName())) {
FileUtils.moveDirectoryToDirectory(dataFiles[i],
new FileManager(context, FileManager.DIARY_ROOT_DIR).getDir()
, true);
}
}
//Remove the diary/temp/
FileUtils.deleteDirectory(new File(diaryFM.getDirAbsolutePath() + "/temp"));
}
return moveIntoNewDir;
}
}
代码示例来源:origin: org.bitbucket.iamkenos/cissnei-commons
public static boolean moveDirs(File source, File dest) {
try {
org.apache.commons.io.FileUtils.moveDirectoryToDirectory(source, dest, true);
return true;
} catch (Exception e) {
LOGGER.error(e.getMessage());
}
return false;
}
代码示例来源:origin: OneBusAway/onebusaway-application-modules
/**
* Copy the sourceDirectory to the given destinationDirectory
*/
public void moveDir(String sourceDirectoryPath, String destinationDirectoryPath) throws IOException{
File sourceDir = new File(sourceDirectoryPath);
File destinationDir = new File(destinationDirectoryPath);
FileUtils.moveDirectoryToDirectory(sourceDir, destinationDir, true);
}
代码示例来源:origin: 3zamn/kingMicro
public static void moveFile(File resFile, String distFolder) throws IOException {
if (resFile != null) {
File distFile = new File(distFolder);
if (resFile.isDirectory()) {
FileUtils.moveDirectoryToDirectory(resFile, distFile, true);
} else if (resFile.isFile()) {
FileUtils.moveFileToDirectory(resFile, distFile, true);
}
} else {
throw new IOException("resFile is null and distFolder: " + distFolder);
}
}
代码示例来源:origin: awslabs/mxnet-model-server
private static void moveToTopLevel(File from, File to) throws IOException {
File[] list = from.listFiles();
if (list != null) {
for (File file : list) {
if (file.isDirectory()) {
FileUtils.moveDirectoryToDirectory(file, to, false);
} else {
FileUtils.moveFileToDirectory(file, to, false);
}
}
}
}
代码示例来源:origin: org.apache.geode/gemfire-core
public void renameExistingSharedConfigDirectory() {
File configDirFile = new File(CONFIG_DIR_PATH);
if (configDirFile.exists()) {
String configDirFileName2 = CLUSTER_CONFIG_ARTIFACTS_DIR_NAME + new SimpleDateFormat("yyyyMMddhhmm").format(new Date()) + "." + System.nanoTime();
File configDirFile2 = new File(FilenameUtils.concat(configDirFileName2, configDirFileName2));
try {
FileUtils.moveDirectoryToDirectory(configDirFile, configDirFile2, true);
} catch (IOException e) {
logger.info(e);
}
}
}
/***
代码示例来源:origin: 3zamn/kingMicro
public static synchronized void moveFileForce(File resFile,String distFolder) throws IOException{
File distFile = new File(distFolder);
if (resFile.isDirectory()) {
FileUtils.moveDirectoryToDirectory(resFile, distFile, true);
} else if (resFile.isFile()) {
File destFile = new File(distFolder, resFile.getName());
if (destFile.exists()){
destFile.delete();
}
FileUtils.moveFileToDirectory(resFile, distFile, true);
}
}
/**
代码示例来源:origin: com.atlassian.jira/jira-core
private void moveOldIndexSnapshots()
{
try
{
FileUtils.moveDirectoryToDirectory(getSnapshotImportDirectory(), getSnapshotArchiveDirectory(), true);
}
catch (IOException ex)
{
LOG.error("Could not archive snapshot directory", ex);
}
}
代码示例来源:origin: com.atlassian.jira/jira-core
private void replaceIndexes(final File workDir) throws IOException
{
// Ensure the indexing directory is empty
File indexDirectory = new File(indexPathManager.getIndexRootPath());
// Delete the JIRA specific indexes. If plugins have added others, we don't want to blow them away
FileUtils.deleteDirectory(new File(indexPathManager.getIssueIndexPath()));
FileUtils.deleteDirectory(new File(indexPathManager.getCommentIndexPath()));
FileUtils.deleteDirectory(new File(indexPathManager.getChangeHistoryIndexPath()));
FileUtils.deleteDirectory(new File(indexPathManager.getWorklogIndexPath()));
FileUtils.deleteDirectory(new File(indexPathManager.getSharedEntityIndexPath()));
if (!indexDirectory.exists())
{
indexDirectory.mkdir();
}
FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.ISSUES_SUBDIR), indexDirectory, true);
FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.COMMENTS_SUBDIR), indexDirectory, true);
FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.CHANGE_HISTORY_SUBDIR), indexDirectory, true);
FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.WORKLOGS_SUBDIR), indexDirectory, true);
FileUtils.moveDirectoryToDirectory(new File(workDir, IndexPathManager.Directory.ENTITIES_SUBDIR), indexDirectory, true);
}
}
代码示例来源:origin: org.onosproject/onlab-thirdparty
moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
moveFileToDirectory(src, destDir, createDestDir);
代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.io
/**
* Moves a file or directory to the destination directory.
* <p>
* When the destination is on another file system, do a "copy and delete".
*
* @param src the file or directory to be moved
* @param destDir the destination directory
* @param createDestDir If <code>true</code> create the destination directory,
* otherwise if <code>false</code> throw an IOException
* @throws NullPointerException if source or destination is <code>null</code>
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs moving the file
* @since Commons IO 1.4
*/
public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException {
if (src == null) {
throw new NullPointerException("Source must not be null");
}
if (destDir == null) {
throw new NullPointerException("Destination must not be null");
}
if (!src.exists()) {
throw new FileNotFoundException("Source '" + src + "' does not exist");
}
if (src.isDirectory()) {
moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
moveFileToDirectory(src, destDir, createDestDir);
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-io
/**
* Moves a file or directory to the destination directory.
* <p>
* When the destination is on another file system, do a "copy and delete".
*
* @param src the file or directory to be moved
* @param destDir the destination directory
* @param createDestDir If <code>true</code> create the destination directory,
* otherwise if <code>false</code> throw an IOException
* @throws NullPointerException if source or destination is <code>null</code>
* @throws IOException if source or destination is invalid
* @throws IOException if an IO error occurs moving the file
* @since Commons IO 1.4
*/
public static void moveToDirectory(File src, File destDir, boolean createDestDir) throws IOException {
if (src == null) {
throw new NullPointerException("Source must not be null");
}
if (destDir == null) {
throw new NullPointerException("Destination must not be null");
}
if (!src.exists()) {
throw new FileNotFoundException("Source '" + src + "' does not exist");
}
if (src.isDirectory()) {
moveDirectoryToDirectory(src, destDir, createDestDir);
} else {
moveFileToDirectory(src, destDir, createDestDir);
}
}
代码示例来源:origin: dankurka/gwtphonegap
@Override
public FileSystemEntryDTO moveDirectory(String fullPath, String newParent, String newName) throws FileErrorException {
File basePath = new File(path);
File directory = new File(basePath, fullPath);
ensureLocalRoot(basePath, directory);
ensureLocalRoot(basePath, directory);
File baseDir = new File(basePath, newParent);
ensureLocalRoot(basePath, baseDir);
File newDir = new File(baseDir, newParent);
try {
FileUtils.moveDirectoryToDirectory(directory, newDir, true);
FileSystemEntryDTO dto = new FileSystemEntryDTO();
dto.setFile(false);
String absolutePath = newDir.getAbsolutePath();
String tmpPath = absolutePath.substring(path.length(), absolutePath.length());
dto.setFullPath(tmpPath);
dto.setName(directory.getName());
return dto;
} catch (IOException e) {
logger.log(Level.SEVERE, "can not move directory", e);
throw new FileErrorException(FileError.INVALID_STATE_ERR);
}
}
代码示例来源:origin: org.xworker/xworker_core
public static void moveDirectoryToDirectory(ActionContext actionContext) throws IOException{
Thing self = actionContext.getObject("self");
File srcDir = getFile(self, "getSrcDir", actionContext);
File destDir = getFile(self, "getDestDir", actionContext);
Boolean createDestDir = (Boolean) self.doAction("getCreateDestDir", actionContext);
FileUtils.moveDirectoryToDirectory(srcDir, destDir, createDestDir);
}
内容来源于网络,如有侵权,请联系作者删除!