List of usage examples for org.apache.commons.io FileUtils copyFile
public static void copyFile(File srcFile, File destFile) throws IOException
From source file:it.geosolutions.geobatch.unredd.script.util.FileManager.java
/** * @deprecated use apache FileUtils directly *///from w w w . j a v a2 s .c o m public static String copyfile(String destDir, String destFileName, String srcFileName) { File source = new File(srcFileName); File dest = new File(destDir, destFileName); try { FileUtils.copyFile(source, dest); LOGGER.info("File copied: " + source + " --> " + dest); } catch (IOException ex) { LOGGER.warn("Error copying file: " + source + " --> " + dest, ex); return null; } // TODO: check original return line return dest.toString(); }
From source file:functions.UploadImage.java
/** * Upload une image sur le serveur./*from w w w . ja va 2s. com*/ * Vrifie au pralable que c'est bien un fichier image. * @param filePart : l'image uploader * @return l'image si l'image est valide, null sinon */ public static Image upload(FilePart filePart) throws IOException { if (isImage(filePart)) { File image = filePart.getFile(); String fileName = filePart.getFilename(); Image i = new Image(fileName); String path = Play.application().configuration().getString("image.path") + i.image_chemin; File destinationFile = new File(path); FileUtils.copyFile(image, destinationFile); i.save(); return i; } else return null; }
From source file:com.thinkit.operationsys.util.FileUtil.java
/** * @param topath // w w w . ja va 2s . co m * @param frompath * @throws IOException */ public static void startCopy(String src, String dest) throws IOException { System.out.println("copy"); //?? File srcfile = new File(src); File destfile = new File(dest); if (srcfile.exists() && destfile.exists()) { FileUtils.copyFile(srcfile, destfile); } else { srcfile.getParentFile().mkdirs(); try { srcfile.createNewFile(); } catch (IOException e) { logger.info("create file error"); e.printStackTrace(); } destfile.getParentFile().mkdirs(); try { destfile.createNewFile(); } catch (IOException e) { logger.info("create file error"); e.printStackTrace(); } } }
From source file:com.chinarewards.gwt.license.util.ImageDisposeUtil.java
/** * @param imgsrc /*from w w w .j a v a 2 s .c o m*/ * @param imgdist ? * @param widthdist * @param heightdist * @param int benchmark :0,12 * */ public static void reduceImg(String imgsrc, String imgdist, int widthdist, int heightdist, int benchmark) { try { // System.out.println("*******widthdist********:"+widthdist); // System.out.println("*******heightdist********:"+heightdist); // System.out.println("*******benchmark********:"+benchmark); File srcfile = new File(imgsrc); if (!srcfile.exists()) { return; } Image src = javax.imageio.ImageIO.read(srcfile); int width = src.getWidth(null); int height = src.getHeight(null); if (width <= widthdist && height <= heightdist) { // SysUtil.cpoyFile(imgsrc, imgdist); FileUtils.copyFile(new File(imgsrc), new File(imgdist)); return; } // float wh = (float) width / (float) height; if (benchmark == 0) { if (wh > 1) { float tmp_heigth = (float) widthdist / wh; BufferedImage tag = new BufferedImage(widthdist, (int) tmp_heigth, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src, 0, 0, widthdist, (int) tmp_heigth, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } else { float tmp_width = (float) heightdist * wh; BufferedImage tag = new BufferedImage((int) tmp_width, heightdist, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src, 0, 0, (int) tmp_width, heightdist, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } if (benchmark == 1) { float tmp_heigth = (float) widthdist / wh; BufferedImage tag = new BufferedImage(widthdist, (int) tmp_heigth, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src, 0, 0, widthdist, (int) tmp_heigth, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } if (benchmark == 2) { float tmp_width = (float) heightdist * wh; BufferedImage tag = new BufferedImage((int) tmp_width, heightdist, BufferedImage.TYPE_INT_RGB); tag.getGraphics().drawImage(src, 0, 0, (int) tmp_width, heightdist, null); FileOutputStream out = new FileOutputStream(imgdist); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); encoder.encode(tag); out.close(); } } catch (IOException ex) { logger.error(ex); } }
From source file:asciidoc.maven.plugin.tools.FileHelper.java
public static boolean copy(File _in, File _out) { try {//from w ww. j av a 2s . c o m FileUtils.copyFile(_in, _out); return true; } catch (IOException e) { log.error("File copy error", e); return false; } }
From source file:com.netease.seed.driver.tools.LogTools.java
public static String screenShot(SeedDriver driver) { String dir = "screenshot"; String time = new SimpleDateFormat("yyyyMMdd-HHmmss").format(new Date()); String screenShotPath = dir + File.separator + time + ".png"; WebDriver augmentedDriver = null;/*from w w w .j av a 2 s. c om*/ augmentedDriver = driver.getBrowserCore(); augmentedDriver = new Augmenter().augment(driver.getBrowserCore()); try { File sourceFile = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(sourceFile, new File(screenShotPath)); } catch (Exception e) { e.printStackTrace(); return "Failed to screenshot"; } return screenShotPath; }
From source file:com.ethnos.SENNUploadAction.java
public String execute() throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); String destPath = "..\\Upload"; try {/* w ww . jav a 2s . co m*/ File destFile = new File(destPath, t1FileName); FileUtils.copyFile(getT1(), destFile); } catch (Exception e) { request.setAttribute("err", "Sorry, file can't be uploaded at this moment!!!"); return "error"; } request.setAttribute("msg", "File uploaded successfully!!!"); return "success"; }
From source file:dao.CopyDirDao.java
public void copyDir(String src, String dest) { File source = new File(src); dest = dest + File.separator + source.getName(); File destination = new File(dest); destination.mkdir();//w w w . j a v a2 s . co m String files[] = source.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); try { //recursive copy FileUtils.copyFile(srcFile, destFile); } catch (IOException ex) { } } }
From source file:com.thoughtworks.go.plugin.infra.commons.GoFileSystem.java
public void copyFile(File srcFile, File destFile) throws IOException { FileUtils.copyFile(srcFile, destFile); }
From source file:gov.nih.nci.calims2.business.storage.StorageServiceImpl.java
/** * {@inheritDoc}// w w w. ja va2 s . c o m * * @throws StorageServiceException */ public File get(Document document, File dir) throws StorageServiceException { File inputFile = new File(document.getUniversalResourceLocator()); File outputFile; try { outputFile = File.createTempFile("LPGLIMS", "", dir); FileUtils.copyFile(inputFile, outputFile); } catch (IOException e) { throw new StorageServiceException("Error saving file from storage" + e.getMessage()); } return outputFile; }