List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:de.flapdoodle.embedmongo.Files.java
public static File createTempDir(String prefix) throws IOException { File tempDir = new File(System.getProperty("java.io.tmpdir")); File tempFile = new File(tempDir, prefix + "-" + UUID.randomUUID().toString()); if (!tempFile.mkdir()) throw new IOException("Could not create Tempdir: " + tempFile); return tempFile; }
From source file:Main.java
public static void checkStorageDir() { File storageDir = new File(Environment.getExternalStorageDirectory() + "/Android"); if (!storageDir.exists()) storageDir.mkdir(); storageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data"); if (!storageDir.exists()) storageDir.mkdir();//from w w w . j a va2 s .c o m storageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/com.nowsci.odm"); if (!storageDir.exists()) storageDir.mkdir(); storageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/com.nowsci.odm/.storage"); if (!storageDir.exists()) storageDir.mkdir(); }
From source file:org.jboss.fuse.examples.HL7ConsumerRouteTest.java
@BeforeClass public static void cleanDirectories() { File auditDir = new File("./target/audit"); if (auditDir.exists()) { FileUtil.removeDir(auditDir);// w w w . j av a 2 s . c o m } auditDir.mkdir(); }
From source file:net.sf.sripathi.ws.mock.util.FileUtil.java
public static void createFilesAndFolder(String root, ZipFile zip) { @SuppressWarnings("unchecked") Enumeration<ZipEntry> entries = (Enumeration<ZipEntry>) zip.entries(); Set<String> files = new TreeSet<String>(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().toLowerCase().endsWith(".wsdl") || entry.getName().toLowerCase().endsWith(".xsd")) files.add(entry.getName());/*from ww w . j av a 2 s.co m*/ } File rootFolder = new File(root); if (!rootFolder.exists()) { throw new MockException("Unable to create file - " + root); } for (String fileStr : files) { String folder = root; String[] split = fileStr.split("/"); if (split.length > 1) { for (int i = 0; i < split.length - 1; i++) { folder = folder + "/" + split[i]; File f = new File(folder); if (!f.exists()) { f.mkdir(); } } } File file = new File(folder + "/" + split[split.length - 1]); FileOutputStream fos = null; InputStream zipStream = null; try { fos = new FileOutputStream(file); zipStream = zip.getInputStream(zip.getEntry(fileStr)); fos.write(IOUtils.toByteArray(zipStream)); } catch (Exception e) { throw new MockException("Unable to create file - " + fileStr); } finally { try { fos.close(); } catch (Exception e) { } try { zipStream.close(); } catch (Exception e) { } } } }
From source file:fr.gael.dhus.util.UnZip.java
public static void unCompress(String zip_file, String output_folder) throws IOException, CompressorException, ArchiveException { ArchiveInputStream ais = null;/* w w w . j av a 2 s. c o m*/ ArchiveStreamFactory asf = new ArchiveStreamFactory(); FileInputStream fis = new FileInputStream(new File(zip_file)); if (zip_file.toLowerCase().endsWith(".tar")) { ais = asf.createArchiveInputStream(ArchiveStreamFactory.TAR, fis); } else if (zip_file.toLowerCase().endsWith(".zip")) { ais = asf.createArchiveInputStream(ArchiveStreamFactory.ZIP, fis); } else if (zip_file.toLowerCase().endsWith(".tgz") || zip_file.toLowerCase().endsWith(".tar.gz")) { CompressorInputStream cis = new CompressorStreamFactory() .createCompressorInputStream(CompressorStreamFactory.GZIP, fis); ais = asf.createArchiveInputStream(new BufferedInputStream(cis)); } else { try { fis.close(); } catch (IOException e) { LOGGER.warn("Cannot close FileInputStream:", e); } throw new IllegalArgumentException("Format not supported: " + zip_file); } File output_file = new File(output_folder); if (!output_file.exists()) output_file.mkdirs(); // copy the existing entries ArchiveEntry nextEntry; while ((nextEntry = ais.getNextEntry()) != null) { File ftemp = new File(output_folder, nextEntry.getName()); if (nextEntry.isDirectory()) { ftemp.mkdir(); } else { FileOutputStream fos = FileUtils.openOutputStream(ftemp); IOUtils.copy(ais, fos); fos.close(); } } ais.close(); fis.close(); }
From source file:net.rim.ejde.internal.util.RIAUtils.java
public static void initDLLs() { IPath dllStoreLocation = ContextManager.PLUGIN.getStateLocation().append("installDlls"); //$NON-NLS-1$ File dllStoreFile = dllStoreLocation.toFile(); if (!dllStoreFile.exists()) dllStoreFile.mkdir(); InputStream inputStream;//from ww w. j a v a 2 s . c o m OutputStream outputStream; File dllFile; byte[] buf; int numbytes; URL bundUrl; for (String dllFileName : dllNames) { inputStream = null; outputStream = null; try { dllFile = dllStoreLocation.append(dllFileName).toFile(); Bundle bundle = ContextManager.PLUGIN.getBundle(); if (!dllFile.exists() || bundle.getLastModified() > dllFile.lastModified()) { bundUrl = bundle.getResource(dllFileName); if (bundUrl == null) continue; inputStream = bundUrl.openStream(); outputStream = new FileOutputStream(dllFile); buf = new byte[4096]; numbytes = 0; while ((numbytes = inputStream.read(buf)) > 0) outputStream.write(buf, 0, numbytes); } } catch (IOException t) { _log.error(t.getMessage(), t); } finally { try { if (inputStream != null) inputStream.close(); if (outputStream != null) outputStream.close(); } catch (IOException t) { _log.error(t.getMessage(), t); } } } // end for }
From source file:com.enonic.esl.io.FileUtil.java
public static File createTempDir(String name) { File dir = new File(System.getProperty("java.io.tmpdir"), name); dir.mkdir(); return dir;//from ww w . ja va2s . c o m }
From source file:com.nextep.designer.beng.services.BENGServices.java
/** * Generates the artefact without any of its dependency * /*from w ww . ja v a 2 s . co m*/ * @see com.nextep.designer.beng.model.IDeliveryItem#generateArtefact(java.lang.String) */ public static void generateArtefact(IDeliveryModule module, String directoryTarget) { // Generating outputs String exportLoc = directoryTarget + File.separator + module.getName(); File f = new File(exportLoc); f.mkdir(); // Resetting descriptor as it should not be possible // to deploy a partially generated release FileUtils.writeToFile(exportLoc + File.separator + "delivery.xml", ""); //$NON-NLS-1$ //$NON-NLS-2$ // Generating folders for (DeliveryType t : DeliveryType.values()) { File typeFolder = new File(exportLoc + File.separator + t.getFolderName()); typeFolder.mkdir(); } // Generating delivery items for (IDeliveryItem<?> i : module.getDeliveryItems()) { i.generateArtefact(exportLoc); } // Copying external files // for(IExternalFile ext : module.getExternalFiles()) { // final String originalFilePath = ext.getDirectory(); // + File.separator + ext.getName(); // File exportedFile = new File(exportLoc + File.separator + // DeliveryType.CUSTOM.getFolderName() + File.separator + ext.getName()); // File originalFile = new File(originalFilePath); // if(!originalFile.exists() || !originalFile.isFile()) { // throw new ErrorException("The external file '" + originalFilePath + "' no more exists."); // } // try { // copyFile(originalFile, exportedFile); // } catch( IOException e) { // throw new ErrorException("Problems while copying external file '" + originalFilePath + // "' into delivery module. Exception message was: " + e.getMessage(),e); // } // } // Generating delivery descriptor FileUtils.writeToFile(exportLoc + File.separator + "delivery.xml", module.generateDescriptor()); //$NON-NLS-1$ }
From source file:com.thoughtworks.go.helpers.FileSystemUtils.java
public static File createDirectory(String directoryName, String parent) { File directory = new File(getTestRootDir(), parent + File.separator + directoryName); deleteDirectory(directory);// ww w. j a v a2s . c om directory.mkdir(); directory.deleteOnExit(); return directory; }
From source file:Main.java
public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { //if directory not exists, create it if (!dest.exists()) { dest.mkdir(); }//from w w w. j ava 2s . c om //list all the directory contents String files[] = src.list(); for (String file : files) { //construct the src and dest file structure File srcFile = new File(src, file); File destFile = new File(dest, file); //recursive copy copyFolder(srcFile, destFile); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; //copy the file content in bytes while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }