Example usage for java.io File renameTo

List of usage examples for java.io File renameTo

Introduction

In this page you can find the example usage for java.io File renameTo.

Prototype

public boolean renameTo(File dest) 

Source Link

Document

Renames the file denoted by this abstract pathname.

Usage

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

private boolean renameReportAndFolder(File srcFile, File destFile) {
    // rename base file
    boolean result = srcFile.renameTo(destFile);
    // rename sub-files
    if (result && destFile.isDirectory()) {
        String srcName = srcFile.getName();
        String destName = destFile.getName();

        FilenameFilter reportNameFilter = new ReportFilenameFilter(srcName);
        File[] subFiles = destFile.listFiles(reportNameFilter);
        for (File subFile : subFiles) {
            File newSubFile = new File(subFile.getParentFile(), destName);
            result &= subFile.renameTo(newSubFile);
        }/*from  ww w .j a  v  a2s  . c o m*/
    }

    return result;
}

From source file:Access.Downloader.java

public boolean download_nnet() throws JSONException, IOException {
    String fileURL = getURL_model();
    //String saveDir = ".\\data\\model\\";
    try {// w  w  w.  j a v a2 s  . c o m
        nnetFileName = HttpDownloadUtility.downloadFile(fileURL, Data.directoryPath_downloadNnet);
        File file = new File(Data.directoryPath_downloadNnet + nnetFileName);
        file.renameTo(new File(Data.filePath_downloadNnet));
        return true;
    } catch (IOException ex) {
        //ex.printStackTrace();
        System.out.println(Data.error_modelDownloadFailed);
    }
    return false;
}

From source file:com.manning.siia.kitchen.RecipeReadingTest.java

@Test
public void shouldReadFileInDirectoryToMessage() throws IOException {
    File resource = new ClassPathResource("/pilav.xml").getFile();
    //copy/*from  w  w w.ja v a2 s .  c  om*/
    File recipeWriting = recipeBookLocation.newFile("pilav.xml.writing");
    FileUtils.copyFile(resource, recipeWriting);
    //then rename
    final File outFile = recipeBookLocation.newFile("pilav.xml");
    recipeWriting.renameTo(outFile);

    final Message<File> message = (Message<File>) test.receive(2000);
    assertThat(message, is(notNullValue()));
    final File payload = message.getPayload();
    assertThat(payload.getPath(), is(outFile.getPath()));
}

From source file:com.zestedesavoir.zestwriter.model.Content.java

@Override
public void renameTitle(String newTitle) {
    String oldPath = getFilePath();
    Path workspace = Paths.get(getFilePath()).getParent();
    String newPath = FunctionTreeFactory
            .getUniqueDirPath(workspace.toAbsolutePath() + File.separator + ZdsHttp.toSlug(newTitle));
    String newSlug = (new File(newPath)).getName();
    setTitle(newTitle);/*  ww  w .j av a 2  s.c om*/
    setSlug(newSlug);
    File oldDir = new File(oldPath);
    File newDir = new File(newPath);
    if (oldDir.renameTo(newDir)) {
        setBasePath(newPath);
    } else {
        MainApp.getLogger().error("Problme de renommage du titre du conteneur " + newTitle);
    }
}

From source file:com.goodhuddle.huddle.service.impl.file.FileStoreImpl.java

public File moveTempFile(String tempFileId, File dest) throws IOException {
    File tempFile = new File(getHuddleBaseTempDir(), tempFileId);
    if (!tempFile.renameTo(dest)) {
        throw new IOException("Error renaming moving temp file from '" + tempFile + "' to '" + dest + "'");
    }/* ww  w . j  a va 2 s . c o  m*/
    return dest;
}

From source file:net.sourceforge.subsonic.ajax.CoverArtService.java

private void backup(File newCoverFile, File backup) {
    if (newCoverFile.exists()) {
        if (backup.exists()) {
            backup.delete();/*  ww  w.  jav a  2s .  co m*/
        }
        if (newCoverFile.renameTo(backup)) {
            LOG.info("Backed up old image file to " + backup);
        } else {
            LOG.warn("Failed to create image file backup " + backup);
        }
    }
}

From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java

public static void copyExifData(File sourceFile, File destFile) {
    String tempFileName = destFile.getAbsolutePath() + ".tmp";
    File tempFile = null;
    OutputStream tempStream = null;

    try {/* www .ja  v  a 2 s . c om*/
        tempFile = new File(tempFileName);
        TiffOutputSet sourceSet = getSanselanOutputSet(sourceFile);

        // Save data to destination
        tempStream = new BufferedOutputStream(new FileOutputStream(tempFile));
        new ExifRewriter().updateExifMetadataLossless(destFile, tempStream, sourceSet);
        tempStream.close();

        if (destFile.delete()) {
            tempFile.renameTo(destFile);
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (tempStream != null) {
            try {
                tempStream.close();
            } catch (IOException e) {
            }
        }

        if (tempFile != null) {
            if (tempFile.exists()) {
                tempFile.delete();
            }
        }
    }
}

From source file:oz.hadoop.yarn.api.core.ApplicationMasterLauncherImplTests.java

@Test
public void validateWithEmptyClasspathFilters() throws Exception {
    ClassPathResource res = new ClassPathResource("classpath.filters");
    File cpFilterFile = res.getFile();
    File parentFile = cpFilterFile.getParentFile();
    File backup = new File("classpath.filters.old");
    try {// www  .jav a2s .co  m
        cpFilterFile.renameTo(backup);
        File file = new File(parentFile, "classpath.filters");
        file.createNewFile();
        Map<String, Object> applicationSpecification = new HashMap<>();
        applicationSpecification.put(YayaConstants.CONTAINER_SPEC, new HashMap<>());
        ApplicationMasterLauncherImpl<Void> launcher = new ApplicationMasterLauncherImpl<>(
                applicationSpecification);

        Method excludedMethod = ReflectionUtils.getMethodAndMakeAccessible(ApplicationMasterLauncherImpl.class,
                "excluded", String.class);
        String[] cp = System.getProperty("java.class.path").split(":");
        for (String v : cp) {
            File f = new File(v);
            if (!f.isDirectory()) {
                boolean excluded = (boolean) excludedMethod.invoke(launcher, f.getName());
                assertFalse(f.getName(), excluded);
            }
        }
    } finally {
        cpFilterFile.delete();
        File file = new File(parentFile, "classpath.filters");
        backup.renameTo(file);
        assertTrue(file.exists());
        assertTrue(file.length() > 0);
    }
}

From source file:com.goodhuddle.huddle.service.impl.file.FileStoreImpl.java

@Override
public File moveFile(File src, String dest) {
    File destFile = new File(getHuddleBaseDir(), dest);
    src.renameTo(destFile);
    return destFile;
}

From source file:FileTreeFrame.java

public void valueForPathChanged(TreePath path, Object value) {
    File oldFile = (File) path.getLastPathComponent();
    String fileParentPath = oldFile.getParent();
    String newFileName = (String) value;
    File targetFile = new File(fileParentPath, newFileName);
    oldFile.renameTo(targetFile);
    File parent = new File(fileParentPath);
    int[] changedChildrenIndices = { getIndexOfChild(parent, targetFile) };
    Object[] changedChildren = { targetFile };
    fireTreeNodesChanged(path.getParentPath(), changedChildrenIndices, changedChildren);

}