List of usage examples for java.io File renameTo
public boolean renameTo(File dest)
From source file:de.thischwa.pmcms.gui.listener.ListenerEditPersistentPojoProperties.java
private void edit(Shell shell, Site site) { String oldSiteUrl = site.getUrl(); if (DialogManager.startDialogPersitentPojo(shell, site)) { if (!StringUtils.equals(site.getUrl(), oldSiteUrl)) { File dir = PoPathInfo.getSiteDirectory(site); File oldDir = PoPathInfo.getSiteDirectory(oldSiteUrl); oldDir.renameTo(dir); File oldDataFile = SitePersister.getDataFile(oldSiteUrl); oldDataFile.delete();/*from w w w . j a v a2 s .co m*/ } WorkspaceToolBarManager.actionAfterSiteRenamed(site); logger.debug("Properties of site are changed!"); } }
From source file:com.ibm.liberty.starter.service.test.api.v1.ProviderEndpoint.java
@GET @Path("uploads/process") @Produces(MediaType.TEXT_PLAIN)/*from w ww .j ava 2 s . com*/ public String processUploads(@QueryParam("path") String uploadDirectoryPath) throws IOException { File uploadDirectory; if (uploadDirectoryPath == null || !(uploadDirectory = new File(uploadDirectoryPath)).exists()) { return "Couldn't fulfill the request due to internal error"; } List<File> filesListInDir = new ArrayList<File>(); populateFilesList(uploadDirectory, filesListInDir); for (File uploadedFile : filesListInDir) { uploadedFile.renameTo(new File(uploadedFile.getParent() + "/" + uploadedFile.getName() + "_renamed")); } return "success"; }
From source file:DBMS.UpdateFileUpload.java
public static boolean processFile(String path, FileItemStream item, int id) { try {/* w ww. j a v a 2s . co m*/ String check = item.getName(); if (check.endsWith(".jpg") || check.endsWith(".JPG")) { String imstring = "images/" + Integer.toString(id); File f = new File(path + File.separator + imstring); if (!f.exists()) f.mkdir(); File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); String dbimage = imstring + "/a.jpg"; //dc.enterImage(dbimage); //im =dbimage; //System.out.println("Resizing!"); //Resize rz = new Resize(); //rz.resize(dbimage); BufferedImage originalImage = ImageIO.read(savedFile); int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType(); BufferedImage resizeImageJpg = resizeImage(originalImage, type); ImageIO.write(resizeImageJpg, "jpg", savedFile); File rFile = new File(f.getAbsolutePath() + "/a.jpg"); savedFile.renameTo(rFile); ProfileEditDB dc = new ProfileEditDB(); dc.enterImage(id, dbimage); System.out.println("Link Entered to Database!"); return true; } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:com.manning.siia.kitchen.EndToEndIntegrationTest.java
@Test public void shouldCreateAMeal() throws IOException { final TimedPollableChannel timed = new TimedPollableChannel(meals); File resource = new ClassPathResource("/pilav.xml").getFile(); //copy/*from w ww.j a v a 2 s . c o m*/ File recipeWriting = recipeBookLocation.newFile("pilav.xml.writing"); FileUtils.copyFile(resource, recipeWriting); //then rename recipeWriting.renameTo(recipeBookLocation.newFile("pilav.xml")); Message<?> message = timed.receive(3500); assertThat(message, is(notNullValue())); Meal meal = (Meal) message.getPayload(); assertThat(meal.getRecipe().getName(), is("Pilav")); assertThat(meal.isDone(), is(true)); }
From source file:com.hichinaschool.flashcards.libanki.sync.FullSyncer.java
@Override public Object[] download() { InputStream cont;/*from www .j a v a 2 s . com*/ try { HttpResponse ret = super.req("download"); if (ret == null) { return null; } cont = ret.getEntity().getContent(); } catch (IllegalStateException e1) { throw new RuntimeException(e1); } catch (IOException e1) { return null; } String path = AnkiDroidApp.getCollectionPath(); if (mCol != null) { mCol.close(false); mCol = null; } String tpath = path + ".tmp"; if (!super.writeToFile(cont, tpath)) { return new Object[] { "sdAccessError" }; } // first check, if account needs upgrade (from 1.2) try { FileInputStream fis = new FileInputStream(tpath); if (super.stream2String(fis, 15).equals("upgradeRequired")) { return new Object[] { "upgradeRequired" }; } } catch (FileNotFoundException e1) { throw new RuntimeException(e1); } // check the received file is ok mCon.publishProgress(R.string.sync_check_download_file); try { AnkiDb d = AnkiDatabaseManager.getDatabase(tpath); if (!d.queryString("PRAGMA integrity_check").equalsIgnoreCase("ok")) { Log.e(AnkiDroidApp.TAG, "Full sync - downloaded file corrupt"); return new Object[] { "remoteDbError" }; } } catch (SQLiteDatabaseCorruptException e) { Log.e(AnkiDroidApp.TAG, "Full sync - downloaded file corrupt"); return new Object[] { "remoteDbError" }; } finally { AnkiDatabaseManager.closeDatabase(tpath); } // overwrite existing collection File newFile = new File(tpath); if (newFile.renameTo(new File(path))) { return new Object[] { "success" }; } else { return new Object[] { "overwriteError" }; } }
From source file:org.xmlactions.common.io.ResourceUtils.java
/** * Rename a file to a new file name and path * /*from w w w . j a v a2 s .c o m*/ * @param fileNameAndPath * is the existing file * @param newFileNameAndPath * is what we rename it to * @param overWrite * if set true will overwrite an existing file, false wont. * @return true if successfull or false if not */ public static boolean renameFile(String fileNameAndPath, String newFileNameAndPath, boolean overWrite) { File file = new File(fileNameAndPath); if (file.exists() == false) { return (false); // source file does not exist } File newFile = new File(newFileNameAndPath); if (overWrite == false && newFile.exists() == true) { return (false); // unable to overwrite existing file } if (newFile.exists()) { if (newFile.delete() == false) { return (false); // Can't delete file } } if (file.renameTo(newFile) == false) { // Copy file try { copyFile(file, newFile); if (file.delete() == false) { return (false); // can't delete it } } catch (Exception ex) { return (false); // not copied } } if (newFile.setLastModified(file.lastModified()) == false) { return (false); } return (true); // whew }
From source file:com.apkcategorychecker.writer.WriterCSV.java
private void removeBlankLines(String _csvPath) { try {// w ww .j a v a2 s . co m FileReader fr = new FileReader(_csvPath); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter(_csvPath + ".temp"); String line; while ((line = br.readLine()) != null) { //line = line.trim(); // remove leading and trailing whitespace if (line.length() != 0) // don't write out blank lines { fw.write(line, 0, line.length()); fw.append("\r"); } } fr.close(); fw.close(); File old = new File(_csvPath); old.delete(); File clean = new File(_csvPath + ".temp"); clean.renameTo(old); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.willkara.zeteo.filetypes.impl.BaseFileType.java
/** * Renames the specified file./*w w w .j av a 2 s . c o m*/ * * @param f The file to be renamed. * @param newName The new name of the file. * @return True OR False if the file was successfully renamed. */ @Override public boolean renameFile(File f, File newName) { return f.renameTo(newName); }
From source file:com.viettel.dms.download.DownloadFile.java
/** * Download file su dung httpclient request * @param url/*from w ww. j a v a2 s. c o m*/ * @param output * @param tmpDir */ public static void downloadWithHTTPClient(String url, File output, File tmpDir) { File tmp = null; HttpClient httpclient = new DefaultHttpClient(); BufferedOutputStream os = null; BufferedInputStream is = null; try { VTLog.i("DownloadDB", "Downloading url :" + url); tmp = File.createTempFile("download", ".tmp", tmpDir); HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { is = new BufferedInputStream(entity.getContent()); os = new BufferedOutputStream(new FileOutputStream(tmp)); copyStream(is, os); tmp.renameTo(output); tmp = null; httpclient.getConnectionManager().shutdown(); } } catch (IOException e) { VTLog.e("DownloadDB", "Loi download file db " + e.toString()); VTLog.e("UnexceptionLog", VNMTraceUnexceptionLog.getReportFromThrowable(e)); throw new RuntimeException(e); } catch (Exception e) { VTLog.e("DownloadDB", "Loi download file db " + e.toString()); VTLog.e("UnexceptionLog", VNMTraceUnexceptionLog.getReportFromThrowable(e)); throw new RuntimeException(e); } finally { if (tmp != null) { try { tmp.delete(); tmp = null; } catch (Exception ignore) { ; } } if (is != null) { try { is.close(); is = null; } catch (Exception ignore) { ; } } if (os != null) { try { os.close(); os = null; } catch (Exception ignore) { ; } } } }
From source file:download.XBRLFileCleaner.java
/** * Deletes all non xbrl file in the, master directory * * @throws java.io.IOException// ww w. j a v a 2s . co m */ public void deleteNonXBRLFiles() throws IOException { File masterDirectory = new File(XBRLFilePaths.XBRL_FILING_DIRECTORY); // lists all files that are not directories except rfd object files Collection<File> files = FileUtils.listFiles(masterDirectory, new String[] { "zip", "xdr", "xsd", "xml" }, true); // deletes the files that are not xbrl files for (File file : files) { if (!isXBRLFile(file.getName())) { Files.delete(Paths.get(file.getAbsolutePath())); } else { file.renameTo( new File(file.getParent() + File.separatorChar + file.getParentFile().getName() + ".xml")); } } }