List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:io.liuwei.web.StaticContentServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ??//from w ww.j a va2 s . c o m String contentPath = request.getPathInfo(); if (StringUtils.isBlank(contentPath) || "/".equals(contentPath)) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "contentPath parameter is required."); return; } // ??. ContentInfo contentInfo = getContentInfo(contentPath); if (!contentInfo.file.exists()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "file not found."); return; } // ?EtagModifiedSince Header?, ??304,. if (!Servlets.checkIfModifiedSince(request, response, contentInfo.lastModified) || !Servlets.checkIfNoneMatchEtag(request, response, contentInfo.etag)) { return; } // Etag/ Servlets.setExpiresHeader(response, Servlets.ONE_YEAR_SECONDS); Servlets.setLastModifiedHeader(response, contentInfo.lastModified); Servlets.setEtag(response, contentInfo.etag); // MIME response.setContentType(contentInfo.mimeType); // ?Header if (request.getParameter("download") != null) { Servlets.setFileDownloadHeader(response, contentInfo.fileName); } // OutputStream OutputStream output; if (checkAccetptGzip(request) && contentInfo.needGzip) { // outputstream, http1.1 trunked??content-length. output = buildGzipOutputStream(response); } else { // outputstream, content-length. response.setContentLength(contentInfo.length); output = response.getOutputStream(); } // ?,?input file FileUtils.copyFile(contentInfo.file, output); output.flush(); }
From source file:FileTransferPackage.MultiFileUpload.java
public boolean saveACFiles(String path) { for (int i = 0; i < uploadedFiles.size(); ++i) { System.out.println("FILE_NAME: " + getUploadedFilesFileName().get(i)); System.out.println("FILE_CONTENT_TYPE: " + getUploadedFilesContentType().get(i)); File dir = new File(path); if (!dir.exists()) { dir.mkdirs();/* ww w. j av a 2s. c o m*/ } else if (dir.isDirectory()) { //Clear out the directory String[] children = dir.list(); for (String children1 : children) { new File(dir, children1).delete(); } } String name = getUploadedFilesFileName().get(i); String targetDir = name.substring(0, name.length() - 4); File acDir = new File(path + "/" + targetDir); if (!acDir.exists()) { acDir.mkdir(); } try { FileUtils.copyFile(getUploadedFiles().get(i), new File(path + "/" + targetDir + "/" + name)); } catch (IOException ex) { Logger.getLogger(MultiFileUpload.class.getName()).log(Level.SEVERE, null, ex); return false; } } //End-For return true; }
From source file:au.id.hazelwood.xmltvguidebuilder.runner.App.java
private void backupOldOutputFiles(File outFile) throws IOException { for (int i = BACKUP_COUNT; i > 0; i--) { File backup = new File(outFile.getPath() + "." + i); File previousBackup = i > 1 ? new File(outFile.getPath() + "." + (i - 1)) : outFile; if (previousBackup.exists()) { FileUtils.copyFile(previousBackup, backup); }//ww w.j ava 2 s . c om } }
From source file:jp.co.nssol.h5.test.selenium.base.H5TestCase.java
/** * ??????// ww w .ja va 2 s. co m * <p> * ?????????????? */ protected void takeScreenShot() { if (!(driver instanceof TakesScreenshot)) { System.out.println("???????????"); return; } try { File dir = new File(screenShotPath); if (!dir.exists()) { dir.mkdirs(); } File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(scrFile, new File( screenShotPath + "\\" + driver.toString() + "_" + System.currentTimeMillis() + ".png")); } catch (IOException e) { e.printStackTrace(); } }
From source file:gobblin.aws.AWSJobConfigurationManagerTest.java
@Test(enabled = false) private String getJobConfigZipUri(File source) throws IOException { final File destination = new File( StringUtils.substringBeforeLast(source.toString(), File.separator) + File.separator + URI_ZIP_NAME); if (destination.exists()) { if (!destination.delete()) { throw new IOException("Cannot clean destination job conf zip file: " + destination); }// w ww . ja v a 2 s . c o m } FileUtils.copyFile(source, destination); return destination.toURI().toString(); }
From source file:com.swg.parse.docx.OpenFolderAction.java
@Override public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory(new File("C:/")); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (selectedFile != null) { fc.setSelectedFile(selectedFile); }//from w ww.j a v a 2 s . co m int returnVal = fc.showDialog(WindowManager.getDefault().getMainWindow(), "Extract Data"); JFrame jf = new JFrame("Progress Bar"); Container Jcontent = jf.getContentPane(); JProgressBar progressBar = new JProgressBar(); progressBar.setValue(0); progressBar.setStringPainted(true); Jcontent.add(progressBar, BorderLayout.NORTH); jf.setSize(300, 60); jf.setVisible(true); //we needed a new thread for a functional progress bar on the JFrame new Thread(new Runnable() { public void run() { if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); selectedFile = file; FileFilter fileFilter = new WildcardFileFilter("*.docx"); File[] files = selectedFile.listFiles(fileFilter); double cnt = 0, cnt2 = 0; //number of how many .docx is in the folder for (File f : files) { if (!f.getAbsolutePath().contains("~")) cnt2++; } for (File f : files) { cnt++; pathToTxtFile = f.getAbsolutePath().replace(".docx", ".txt"); TxtFile = new File(pathToTxtFile); //---------------------------------------------------- String zipFilePath = "C:\\Users\\fja2\\Desktop\\junk\\Test\\test.zip"; String destDirectory = "C:\\Users\\fja2\\Desktop\\junk\\Test " + cnt; UnzipUtility unzipper = new UnzipUtility(); try { File zip = new File(zipFilePath); File directory = new File(destDirectory); FileUtils.copyFile(f, zip); unzipper.UnzipUtility(zip, directory); zip.delete(); String mediaPath = destDirectory + "/word/media/"; File mediaDir = new File(mediaPath); for (File fil : mediaDir.listFiles()) { FileUtils.copyFile(fil, new File("C:\\Users\\PXT1\\Desktop\\test\\Pictures\\" + f.getName() + "\\" + fil.getName())); } FileUtils.deleteDirectory(directory); } catch (Exception ex) { ex.printStackTrace(); } //---------------------------------------------------- //if the txt file doesn't exist, it tries to convert whatever //can be the txt into the actual txt. if (!TxtFile.exists()) { pathToTxtFile = f.getAbsolutePath().replace(".docx", ""); TxtFile = new File(pathToTxtFile); pathToTxtFile += ".txt"; TxtFile.renameTo(new File(pathToTxtFile)); TxtFile = new File(pathToTxtFile); } String content = ""; String POIContent = ""; try { content = readTxtFile(); version = DetermineVersion(content); NewExtract ext = new NewExtract(); ext.extract(content, f.getAbsolutePath(), version, (int) cnt); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } catch (IOException ex) { Exceptions.printStackTrace(ex); } catch (ParseException ex) { Exceptions.printStackTrace(ex); } double tempProg = (cnt / cnt2) * 100; progressBar.setValue((int) tempProg); System.gc(); } } else { //do nothing } } }).start(); System.gc(); }
From source file:com.bibisco.test.AllTests.java
@BeforeClass public static void cleanProjectsDirectory() throws IOException, ConfigurationException, InterruptedException { FileUtils.copyFile(new File(mStrTestBibiscoDBFilePath), new File(mStrDBFilePath)); FileUtils.cleanDirectory(new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProjectDBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProject2DBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); FileUtils.copyDirectoryToDirectory(new File(mStrTestProject3DBFilePath), new File(BIBISCO_INTERNAL_PROJECTS_DIR)); }