List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:com.ms.commons.test.tool.util.AutoDeleteProjectTaskUtil.java
public static Task wrapAutoDeleteTask(final File project, final Task oldTask) { String userDir = System.getProperty("user.dir"); List<Element> projectElements = ClassPathAccessor.getElementsByXPath(project, "/project"); if ((projectElements == null) || (projectElements.size() != 1)) { System.err.println("File '" + project + "' format error!"); System.exit(-1);/*from ww w . ja v a2 s .co m*/ } final String projectId = projectElements.get(0).getAttributeValue("id"); final String projectExtends = projectElements.get(0).getAttributeValue("extends"); System.out.println("Project id:" + projectId); System.out.println("Project extends:" + projectExtends); final File baseProject = new File(userDir + File.separator + projectExtends); if (!baseProject.exists()) { System.err.println("Base file '" + baseProject + "' not found!"); System.exit(-1); } List<Element> findProjectIdElements = ClassPathAccessor.getElementsByXPath(baseProject, "/project/projects/project[@id='" + projectId + "']"); if ((findProjectIdElements != null) && (findProjectIdElements.size() > 0)) { System.out.println("Find project id in base project file."); return new Task() { @SuppressWarnings("unchecked") public void finish() { boolean hasError = false; File backUpFile = new File(baseProject.getAbsoluteFile() + ".backup"); try { FileUtils.copyFile(baseProject, backUpFile); // XMLAPI List<String> outLines = new ArrayList<String>(); List<String> lines = FileUtils.readLines(baseProject); for (String line : lines) { if (!(line.contains("\"" + projectId + "\""))) { outLines.add(line); } } FileUtils.writeLines(baseProject, outLines); oldTask.finish(); } catch (Exception e) { hasError = true; e.printStackTrace(); } finally { baseProject.delete(); try { FileUtils.copyFile(backUpFile, baseProject); } catch (IOException e) { hasError = true; e.printStackTrace(); } backUpFile.delete(); } if (hasError) { System.exit(-1); } } }; } else { System.out.println("Not find project id in base project file."); } return oldTask; }
From source file:com.github.wasiqb.coteafs.appium.device.DeviceActions.java
/** * @author wasiq.bhamla/*www . j a v a 2 s. c o m*/ * @since Jul 22, 2017 11:03:48 PM * @param srcFiler * @param path */ private static void copyFile(final File source, final String destination) { try { FileUtils.copyFile(source, new File(destination)); } catch (final IOException e) { log.error("Error occurred while capturing screensshot..."); log.catching(e); } }
From source file:com.ppcxy.cyfm.showcase.demos.utilities.io.IODemo.java
@Test public void workWithFileContent() { File file = new File("woop.txt"); File destFile = new File("bar.txt"); try {/*www .j a va 2s . c o m*/ // text -> file, Collection<String>, byte[] ->file FileUtils.writeStringToFile(file, "Hey sailor!\nHaha\n", "UTF-8"); // inputstream -> file InputStream source = IOUtils.toInputStream("Hej", "UTF-8"); FileUtils.copyInputStreamToFile(source, file); // /////////////////////////// // file -> outputstream System.out.println("copy File to outputstream:"); FileUtils.copyFile(file, System.out); // file -> file FileUtils.copyFile(file, destFile); // file -> string System.out.println("File to String:"); System.out.println(FileUtils.readFileToString(file, "UTF-8")); // file -> list<string> System.out.println("File to List<String>:"); List<String> lines = FileUtils.readLines(file, "UTF-8"); for (String string : lines) { System.out.println(string); } } catch (IOException e) { Exceptions.unchecked(e); } }
From source file:com.thomas.domain.util.ScreenshotIt.java
/** * * This method will take the screen shot and compare it with the existing screen shot to check for accuracy * @param lnk_TopNav// ww w.j a v a2 s . c om * @throws java.io.IOException * @throws java.lang.InterruptedException */ public void Screenshot(String lnk_TopNav) throws IOException, InterruptedException { scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); String projectLocation = System.getProperty("user.dir"); File file_actual = new File( projectLocation + "\\src\\main\\resources\\screenshots\\screenshot_" + lnk_TopNav + ".png"); driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS); FileUtils.copyFile(scrFile, file_actual); }
From source file:can.yrt.onebusaway.backup.Backup.java
/** * Performs a backup to the SD card./*from www .j a v a 2 s. c o m*/ * * @param context */ public static String backup(Context context) throws IOException { // We need two things: // 1. The path to the database; // 2. The path on the SD card to the backup file. File backupPath = getBackup(context); FileUtils.copyFile(getDB(context), backupPath); return backupPath.getAbsolutePath(); }
From source file:com.googlecode.t7mp.steps.deployment.CopyJuliJarStep.java
@Override public void execute(Context context) { try {/* w ww.j a va2 s.co m*/ AbstractT7Mojo mojo = context.getMojo(); File juliJarFileSource = new File(TomcatUtil.getBinDirectory(mojo.getCatalinaBase()), JAR_NAME); File juliJarFileDestination = new File(TomcatUtil.getLibDirectory(mojo.getCatalinaBase()), JAR_NAME); FileUtils.copyFile(juliJarFileSource, juliJarFileDestination); } catch (IOException e) { throw new TomcatSetupException(e.getMessage(), e); } }
From source file:com.datatorrent.stram.cli.ApexCliTest.java
@BeforeClass public static void createPackages() { userHome = System.getProperty("user.home"); String newHome = System.getProperty("user.dir") + "/target"; try {// w w w .ja v a 2 s. c o m FileUtils.forceMkdir(new File(newHome + "/.dt")); FileUtils.copyFile( new File(System.getProperty("user.dir") + "/src/test/resources/testAppPackage/dt-site.xml"), new File(newHome + "/.dt/dt-site.xml")); env.put("HOME", newHome); StramTestSupport.setEnv(env); // Set up jar file to use with constructor testFolder.create(); appFile = StramTestSupport.createAppPackageFile(); configFile = StramTestSupport.createConfigPackageFile(new File(testFolder.getRoot(), configJarPath)); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:functionaltests.workflow.JobWorkflowDataspace.java
@Override public Serializable execute(TaskResult... results) throws Throwable { String filename = getIterationIndex() + "_" + getReplicationIndex(); FileUtils.copyFile(new File(filename + ".in"), new File(filename + ".out")); return null;/* ww w.ja v a 2 s.c o m*/ }
From source file:com.atlassian.jira.webtests.ztests.admin.TestImportExport.java
public void testXmlImportFromNonImportDirectory() throws Exception { File data = new File(getEnvironmentData().getXMLDataLocation(), "EmptyJira.xml"); // write new data to temp file File newData = File.createTempFile("testXmlImportFromNonImportDirectory", ".xml"); //This will be created in the /tmp directory try {//ww w .j a va2 s. c o m FileUtils.copyFile(data, newData); tester.gotoPage("secure/admin/XmlRestore!default.jspa"); tester.setWorkingForm("restore-xml-data-backup"); tester.setFormElement("filename", newData.getAbsolutePath()); tester.submit(); tester.assertTextPresent("Could not find file at this location"); } finally { newData.delete(); } }
From source file:com.moodle.test.Toolkit.java
/** * Takes a screenshot and appends a timestamp. * @param fileDest The absolute path to the destination where the files will be saved. * @throws IOException/*from w ww .j av a2 s . co m*/ */ public void takeScreenshotWithTimestamp(String fileDest) throws IOException { WebDriver augmentedDriver = new Augmenter().augment(driver); String timeStamp = new SimpleDateFormat().format(new Date()); File screenshot = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screenshot, new File(fileDest + timeStamp)); }