List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:com.esofthead.mycollab.vaadin.web.ui.AttachmentPanel.java
public List<File> files() { List<File> listFile = null; if (MapUtils.isNotEmpty(fileStores)) { listFile = new ArrayList<>(); for (Map.Entry<String, File> entry : fileStores.entrySet()) { File oldFile = entry.getValue(); File parentFile = oldFile.getParentFile(); File newFile = new File(parentFile, entry.getKey()); if (newFile.exists()) newFile.delete();/*from w w w . j av a 2 s . c o m*/ if (oldFile.renameTo(newFile)) { listFile.add(newFile); } if (listFile.size() <= 0) return null; } } return listFile; }
From source file:jeplus.EPlusWinTools.java
public static int runReadVars(EPlusConfig config, String WorkDir, String rvifile, String freq, String csvfile) { int ExitValue = -99; try {/*from w w w . j a va2 s. c o m*/ Process EPProc; // Run EnergyPlus ReadVarsESO String CmdLine = config.getResolvedReadVars() + " \"" + rvifile + "\" " + freq + " unlimited"; EPProc = Runtime.getRuntime().exec( new String[] { config.getResolvedReadVars(), rvifile, freq, "unlimited" }, null, new File(WorkDir)); // Console logger try (PrintWriter outs = (config.getScreenFile() == null) ? null : new PrintWriter(new FileWriter(WorkDir + "/" + config.getScreenFile(), true));) { if (outs != null) { outs.println("# Calling ReadVarsESO - " + (new SimpleDateFormat()).format(new Date())); outs.println("# Command line: " + WorkDir + ">" + CmdLine); outs.flush(); } StreamPrinter p_out = new StreamPrinter(EPProc.getInputStream(), "OUTPUT", outs); StreamPrinter p_err = new StreamPrinter(EPProc.getErrorStream(), "ERROR"); p_out.start(); p_err.start(); ExitValue = EPProc.waitFor(); p_out.join(); p_err.join(); // Copy the result file (eplusout.csv) to the target csv file name File csv = new File(WorkDir + EPlusConfig.getEPDefOutCSV()); boolean ok = false; // Clear the existing output csv file File csvout = new File(WorkDir + csvfile); if (csvout.exists()) csvout.delete(); // Rename the new csv to the output csv if (csv.exists() && csv.renameTo(csvout)) { ok = true; } if (outs != null) { outs.println("# ReadVarsESO returns: " + ExitValue); outs.println(ok ? csv.getPath() + " renamed to " + csvfile : "Processing " + rvifile + " has failed."); outs.flush(); } } // set it to successful ExitValue = 0; } catch (IOException | InterruptedException ex) { logger.error("Error executing ReadVars.", ex); } return ExitValue; }
From source file:net.sourceforge.jweb.maven.mojo.PropertiesOverideMojo.java
public void execute() throws MojoExecutionException, MojoFailureException { if (disabled) { this.getLog().info("plugin was disabled"); return;//from w ww . ja v a2s. c om } processConfiguration(); if (replacements.isEmpty()) { this.getLog().info("Nothing to replace with"); return; } String name = this.builddir.getAbsolutePath() + File.separator + this.finalName + "." + this.packing;//the final package this.getLog().debug("final artifact: " + name);// the final package try { File finalWarFile = new File(name); File tempFile = File.createTempFile(finalWarFile.getName(), null); tempFile.delete();//check deletion boolean renameOk = finalWarFile.renameTo(tempFile); if (!renameOk) { getLog().error("Can not rename file, please check."); return; } ZipOutputStream out = new ZipOutputStream(new FileOutputStream(finalWarFile)); ZipFile zipFile = new ZipFile(tempFile); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (acceptMime(entry)) { getLog().info("applying replacements for " + entry.getName()); InputStream inputStream = zipFile.getInputStream(entry); String src = IOUtils.toString(inputStream, encoding); //do replacement for (Entry<String, String> e : replacements.entrySet()) { src = src.replaceAll("#\\{" + e.getKey() + "}", e.getValue()); } out.putNextEntry(new ZipEntry(entry.getName())); IOUtils.write(src, out, encoding); inputStream.close(); } else { //not repalce, just put entry back to out zip out.putNextEntry(entry); InputStream inputStream = zipFile.getInputStream(entry); byte[] buf = new byte[512]; int len = -1; while ((len = inputStream.read(buf)) > 0) { out.write(buf, 0, len); } inputStream.close(); continue; } } zipFile.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:edu.washington.iam.registry.rp.XMLMetadata.java
public int writeMetadata() { locker.readLock().lock();//w ww .j a v a2 s .c o m try { URI xUri = new URI(tempUri); File xfile = new File(xUri); FileWriter xstream = new FileWriter(xfile); BufferedWriter xout = new BufferedWriter(xstream); // write header xout.write(xmlStart); xout.write(xmlNotice); // write rps for (int i = 0; i < relyingParties.size(); i++) { RelyingParty rp = relyingParties.get(i); rp.writeXml(xout); xout.write("\n"); } // write trailer xout.write(xmlEnd); xout.close(); } catch (IOException e) { log.error("write io error: " + e); locker.readLock().unlock(); return 1; } catch (URISyntaxException e) { log.error("bad uri error: " + e); locker.readLock().unlock(); return 1; } catch (Exception e) { log.error("write error: " + e); locker.readLock().unlock(); return 1; } // move the temp file to live try { File live = new File(new URI(uri)); File temp = new File(new URI(tempUri)); temp.renameTo(live); } catch (Exception e) { log.info("rename: " + e); } locker.readLock().unlock(); return 0; }
From source file:com.googlecode.psiprobe.model.stats.StatsCollection.java
private void shiftFiles(int index) { if (index >= maxFiles - 1) { new File(makeFile().getAbsolutePath() + "." + index).delete(); } else {/* w w w .ja v a2s. com*/ shiftFiles(index + 1); File srcFile = index == 0 ? makeFile() : new File(makeFile().getAbsolutePath() + "." + index); File destFile = new File(makeFile().getAbsolutePath() + "." + (index + 1)); srcFile.renameTo(destFile); } }
From source file:com.adamrosenfield.wordswithcrosses.net.DerStandardDownloader.java
private void savePuzzle(DerStandardPuzzleMetadata pm) throws IOException { if (pm.isPuzzleAvailable()) { File tempFile = new File(WordsWithCrossesApplication.TEMP_DIR, getFilename(pm.getDate())); IO.save(pm.getPuzzle(), tempFile); File destFile = getTargetFile(pm); if (!tempFile.renameTo(destFile)) { throw new IOException("Failed to rename " + tempFile + " to " + destFile); }//w ww . j ava 2s . c o m } }
From source file:models.charroi.Car.java
public void saveDocs(File doc1, File doc2, File doc3, File doc4, File doc5) { if (doc1 != null) { String ext = "." + FilenameUtils.getExtension(doc1.getAbsolutePath()); new File(Car.DOC_DIR + "doc1-" + this.id + ext).delete(); doc1.renameTo(new File(Car.DOC_DIR + "doc1-" + this.id + ext)); this.doc1 = true; this.doc1Ext = ext; }// ww w . ja va2 s . c om if (doc2 != null) { String ext = "." + FilenameUtils.getExtension(doc2.getAbsolutePath()); new File(Car.DOC_DIR + "doc2-" + this.id + ext).delete(); doc2.renameTo(new File(Car.DOC_DIR + "doc2-" + this.id + ext)); this.doc2 = true; this.doc2Ext = ext; } if (doc3 != null) { String ext = "." + FilenameUtils.getExtension(doc3.getAbsolutePath()); new File(Car.DOC_DIR + "doc3-" + this.id + ext).delete(); doc3.renameTo(new File(Car.DOC_DIR + "doc3-" + this.id + ext)); this.doc3 = true; this.doc3Ext = ext; } if (doc4 != null) { String ext = "." + FilenameUtils.getExtension(doc4.getAbsolutePath()); new File(Car.DOC_DIR + "doc4-" + this.id + ext).delete(); doc4.renameTo(new File(Car.DOC_DIR + "doc4-" + this.id + ext)); this.doc4 = true; this.doc4Ext = ext; } if (doc5 != null) { String ext = "." + FilenameUtils.getExtension(doc5.getAbsolutePath()); new File(Car.DOC_DIR + "doc5-" + this.id + ext).delete(); doc5.renameTo(new File(Car.DOC_DIR + "doc5-" + this.id + ext)); this.doc5 = true; this.doc5Ext = ext; } }
From source file:com.flipkart.phantom.runtime.impl.spring.admin.SPConfigServiceImpl.java
/** * Restores the previous config file, if found * @param handlerName Name of the job/*from w w w .ja va 2 s .com*/ */ private void restorePrevConfigFile(String handlerName) { File configFile = null; try { configFile = this.getHandlerConfig(handlerName).getFile(); } catch (IOException e) { LOGGER.error("IOException while getting HandlerConfigFile", e); } if (configFile.exists()) { configFile.delete(); } File prevFile = new File(configFile.getParent() + "/" + SPConfigServiceImpl.PREV_HANDLER_FILE); if (prevFile.exists()) { prevFile.renameTo(configFile); } }
From source file:com.utiles.files.MetodosFiles.java
public void agregarPrintException(String rutaClaseJava) { // String rutaClaseJava = FILE_PRUEBA; String tmpFileName = FILE_PRUEBA_TEMPORAL; BufferedReader br = null;/*from w ww. j av a 2 s. c o m*/ BufferedWriter bw = null; String nombreClase = null; boolean existePrintException; boolean existeSystemOut; boolean existeLineaComentada; boolean existePrintStack; boolean existeCatch; boolean existenEspaciosEnBlanco; try { br = new BufferedReader(new FileReader(rutaClaseJava)); bw = new BufferedWriter(new FileWriter(tmpFileName)); String line; while ((line = br.readLine()) != null) { if (nombreClase == null) { nombreClase = detectarNombreClase(line); } existePrintException = validarExistenciaEnInicioDeLinea(line, IDENTIFICADOR_PRINT_EXCEPTION); existeSystemOut = validarExistenciaEnInicioDeLinea(line, IDENTIFICADOR_SYSTEM_OUT); existeLineaComentada = validarLineaSinComentario(line); existenEspaciosEnBlanco = validarExistenciaLineaEnBlanco(line); existePrintStack = validarExistenciaPrintStack(line); existeCatch = validarExisteCatch(line); if (existeCatch) { bw.write(line + armarCadenaPrintException(nombreClase) + "\n"); } else { if (!existePrintStack && !existePrintException && !existeSystemOut && !existeLineaComentada && !existenEspaciosEnBlanco) { bw.write(line + "\n"); System.out.println(line + " " + existeLineaComentada + "\n"); } } } } catch (Exception e) { printException("[ MetodosFiles ]", e); return; } finally { try { if (br != null) { br.close(); } } catch (IOException e) { printException("[ MetodosFiles ]", e); } try { if (bw != null) { bw.close(); } } catch (IOException e) { printException("[ MetodosFiles ]", e); // } } // Once everything is complete, delete old file.. File oldFile = new File(rutaClaseJava); oldFile.delete(); // And rename tmp file's name to old file name File newFile = new File(tmpFileName); newFile.renameTo(oldFile); }
From source file:msearch.io.MSFilmlisteLesen.java
public String filmlisteUmbenennen(String dateiFilmliste, ListeFilme listeFilme) { String dest = ""; try {/*from ww w. ja v a2 s . c om*/ if (listeFilme.isEmpty()) { MSLog.fehlerMeldung(312126987, MSLog.FEHLER_ART_PROG, "MSearchIoXmlFilmlisteLesen.filmlisteUmbenennen", "Die Filmliste ist leer."); return ""; } dest = dateiFilmliste + listeFilme.genDateRev(); if (dateiFilmliste.equals(dest)) { return ""; } File fileDest = new File(dest); if (fileDest.exists()) { MSLog.systemMeldung( new String[] { "Filmliste umbenennen: ", "Es gibt schon eine Liste mit dem Datum." }); return ""; } File fileSrc = new File(dateiFilmliste); fileSrc.renameTo(fileDest); fileSrc = null; fileDest = null; } catch (Exception ex) { MSLog.fehlerMeldung(978451206, MSLog.FEHLER_ART_PROG, "MSearchIoXmlFilmlisteLesen.filmlisteUmbenennen", ex); } return dest; }