List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:org.shareok.data.dspacemanager.DspaceJournalDataUtil.java
/** * //from w ww.j a v a 2 s . com * @param file : the uploaded file * @param publisher : journal publisher, e.g. sage or plos * @return : the path of the uploading folder */ public static String saveUploadedData(MultipartFile file, String publisher) { String uploadedFilePath = null; try { String oldFileName = file.getOriginalFilename(); String extension = DocumentProcessorUtil.getFileExtension(oldFileName); oldFileName = DocumentProcessorUtil.getFileNameWithoutExtension(oldFileName); //In the future the new file name will also has the user name String time = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date()); String newFileName = oldFileName + "--" + time + "." + extension; String uploadPath = getDspaceJournalUploadFolderPath(publisher); if (null != uploadPath) { File uploadFolder = new File(uploadPath); if (!uploadFolder.exists()) { uploadFolder.mkdir(); } File uploadTimeFolder = new File(uploadPath + File.separator + time); if (!uploadTimeFolder.exists()) { uploadTimeFolder.mkdir(); } } uploadedFilePath = uploadPath + File.separator + time + File.separator + newFileName; File uploadedFile = new File(uploadedFilePath); file.transferTo(uploadedFile); } catch (Exception ex) { Logger.getLogger(DspaceJournalDataUtil.class.getName()).log(Level.SEVERE, null, ex); } return uploadedFilePath; }
From source file:org.wso2.am.integration.services.jaxrs.peoplesample.Starter.java
private static File createBaseDirectory() throws IOException { final File base = File.createTempFile("tmp-", "", new File("/home/dharshana/reaserch/jetty/jetty2/src/main/resources")); if (!base.delete()) { throw new IOException("Cannot (re)create base folder: " + base.getAbsolutePath()); }/*from w w w .j a v a 2 s. c o m*/ if (!base.mkdir()) { throw new IOException("Cannot create base folder: " + base.getAbsolutePath()); } return base; }
From source file:com.guye.baffle.util.OS.java
public static File createTempDirectory() throws BaffleException { try {// www. jav a 2s. c om File tmp = File.createTempFile("BRUT", null); if (!tmp.delete()) { throw new BaffleException("Could not delete tmp file: " + tmp.getAbsolutePath()); } if (!tmp.mkdir()) { throw new BaffleException("Could not create tmp dir: " + tmp.getAbsolutePath()); } return tmp; } catch (IOException ex) { throw new BaffleException("Could not create tmp dir", ex); } }
From source file:de.uni_hildesheim.sse.ant.versionReplacement.PluginVersionReplacer.java
/** * Unpacks an existing JAR/Zip archive.// ww w.ja va 2s . c o m * * @param zipFile The Archive file to unzip. * @param outputFolder The destination folder where the unzipped content shall be saved. * @see <a href="http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/"> * http://www.mkyong.com/java/how-to-decompress-files-from-a-zip-file/</a> */ private static void unZipIt(File zipFile, File outputFolder) { byte[] buffer = new byte[1024]; try { // create output directory is not exists File folder = outputFolder; if (folder.exists()) { FileUtils.deleteDirectory(folder); } folder.mkdir(); // get the zip file content ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); // get the zipped file list entry ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder, fileName); // create all non exists folders // else you will hit FileNotFoundException for compressed folder new File(newFile.getParent()).mkdirs(); if (!ze.isDirectory()) { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:com.jaeksoft.searchlib.util.FileUtils.java
public final static File createTempDirectory(String prefix, String suffix) throws IOException { final File temp; temp = File.createTempFile(prefix, suffix); if (!temp.delete()) throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); if (!temp.mkdir()) throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); return temp;/* w w w . j a v a 2 s . com*/ }
From source file:fi.solita.phantomrunner.util.FileUtils.java
/** * Extracts the given resource to user's temporary directory (by creating a unique directory underneath * it). Will delete that file and created directories on system exit if deleteOnExit is true. * /* www .j a va 2 s. c o m*/ * @param resource Resource to be extracted * @param subPath Slash (character '/') separated path of the sub-directories which should be created * @param deleteOnExit If the resource and created sub-directories should be deleted * * @return File handle to the created file in the temporary directory */ public static File extractResourceToTempDirectory(Resource resource, String subPath, boolean deleteOnExit) throws IOException { final File tempDir = Files.createTempDir(); if (deleteOnExit) tempDir.deleteOnExit(); File lastDir = tempDir; for (String subDir : subPath.split("/")) { // if the subPath starts or ends with '/' we'll get empty strings too if (StringUtils.hasLength(subDir)) { lastDir = new File(lastDir, subDir); lastDir.mkdir(); if (deleteOnExit) lastDir.deleteOnExit(); } } final File resFile = new File(lastDir, resource.getFilename()); resFile.createNewFile(); if (deleteOnExit) resFile.deleteOnExit(); IOUtil.copy(resource.getInputStream(), new FileWriter(resFile), "UTF-8"); return resFile; }
From source file:com.ecofactor.qa.automation.platform.util.FileUtil.java
/** * Create a new Folder if it is not exists. * @param dirPath the dir path//from w ww.j a va2 s. co m */ public static void createDir(final String dirPath) { final File file = new File(dirPath); if (!file.exists()) { if (file.mkdir()) { LogUtil.setLogString("Directory Created", true); } else { LogUtil.setLogString("Failed to create directory!", true); } } }
From source file:uploadProcess.java
public static boolean decrypt(File inputFolder, String fileName, String patientID, String viewKey) { try {//from ww w . j av a 2s .c o m String ukey = GetKey.getPatientKey(patientID); if (viewKey.equals(ukey)) { //Download File from Cloud.. DropboxUpload download = new DropboxUpload(); download.downloadFile(fileName, StoragePath.getDropboxDir() + patientID, inputFolder); File inputFile = new File(inputFolder.getAbsolutePath() + File.separator + fileName); FileInputStream fis = new FileInputStream(inputFile); File outputFolder = new File(inputFolder.getAbsolutePath() + File.separator + "temp"); if (!outputFolder.exists()) { outputFolder.mkdir(); } FileOutputStream fos = new FileOutputStream( outputFolder.getAbsolutePath() + File.separator + fileName); byte[] k = ukey.getBytes(); SecretKeySpec key = new SecretKeySpec(k, "AES"); Cipher enc = Cipher.getInstance("AES"); enc.init(Cipher.DECRYPT_MODE, key); CipherOutputStream cos = new CipherOutputStream(fos, enc); byte[] buf = new byte[1024]; int read; while ((read = fis.read(buf)) != -1) { cos.write(buf, 0, read); } fis.close(); fos.flush(); cos.close(); return true; } else { return false; } } catch (Exception e) { System.out.println("Error: " + e); } return false; }
From source file:localization.split.java
public static Vector<String> readzipfile(String filepath) { Vector<String> v = new Vector<String>(); byte[] buffer = new byte[1024]; String outputFolder = filepath.substring(0, filepath.lastIndexOf(".")); System.out.println(outputFolder); try {/*from ww w . ja va2s. co m*/ File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(filepath)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + "\\" + fileName); v.addElement(newFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (Exception e) { } return v; }
From source file:Functions.FileUpload.java
public static boolean processFile(String path, FileItemStream item, String houseId, String owner) { if ("".equals(item.getName())) { return false; }// w ww. j av a 2 s . c o m String nm = houseId + item.getName(); System.out.println("nm =====================" + nm); try { File f = new File(path + File.separator + "images/"); if (!f.exists()) {//den uparxei kan o fakelos opote den einai sthn database tpt! System.out.println("Mphke sthn if den exists"); f.mkdir(); File savedFile = new File(f.getAbsoluteFile() + File.separator + nm); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } else { System.out.println("Mphke sthn if exists"); if (database_common_functions.isHouseImageInDatabase(houseId, nm) == 1) { //overwrites current image with name nm. System.out.println("Mphke na kanei overwrite t arxeio"); FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); return true; } else { FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; }