List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
private static void copyFileOrDirectory(File source, File destination) throws IOException { if (source.isDirectory()) { if (!destination.exists()) { destination.mkdirs(); }// w w w . j a v a 2 s. com File[] files = source.listFiles(); for (File f : files) { copyFileOrDirectory(f, new File(destination, f.getName())); } } else { copyFile(source, destination); } }
From source file:Main.java
public static File getConfigFile(final String filename) { final File configFolder = new File(Environment.getExternalStorageDirectory(), CARDBOARD_CONFIG_FOLDER); if (!configFolder.exists()) { configFolder.mkdirs(); } else if (!configFolder.isDirectory()) { final String value = String.valueOf(String.valueOf(configFolder)); throw new IllegalStateException( new StringBuilder().append("Folder ").append(value).append(" already exists").toString()); }//from www . j a v a 2 s .c om return new File(configFolder, filename); }
From source file:com.linkedin.databus.groupleader.impl.zkclient.LeaderElectUtils.java
public static ZkServer startZkServer(String zkTestDataRootDir, int machineId, int port, int tickTime) throws IOException { File zkTestDataRootDirFile = new File(zkTestDataRootDir); zkTestDataRootDirFile.mkdirs(); String dataPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/data"; String logPath = zkTestDataRootDir + "/" + machineId + "/" + port + "/log"; FileUtils.deleteDirectory(new File(dataPath)); FileUtils.deleteDirectory(new File(logPath)); IDefaultNameSpace mockDefaultNameSpace = new IDefaultNameSpace() { @Override//from ww w . j av a2 s . c o m public void createDefaultNameSpace(ZkClient zkClient) { } }; LOG.info("Starting local zookeeper on port=" + port + "; dataPath=" + dataPath); ZkServer zkServer = new ZkServer(dataPath, logPath, mockDefaultNameSpace, port, tickTime); zkServer.start(); return zkServer; }
From source file:edu.uci.ics.asterix.installer.transaction.RecoveryIT.java
@BeforeClass public static void setUp() throws Exception { File outdir = new File(PATH_ACTUAL); outdir.mkdirs(); asterixInstallerPath = new File(System.getProperty("user.dir")); installerTargetPath = new File(asterixInstallerPath, "target"); managixHomeDirName = installerTargetPath.list(new FilenameFilter() { @Override//from ww w . j a v a2 s . c om public boolean accept(File dir, String name) { return new File(dir, name).isDirectory() && name.startsWith("asterix-installer") && name.endsWith("binary-assembly"); } })[0]; managixHomePath = new File(installerTargetPath, managixHomeDirName).getAbsolutePath(); LOGGER.info("MANAGIX_HOME=" + managixHomePath); pb = new ProcessBuilder(); env = pb.environment(); env.put("MANAGIX_HOME", managixHomePath); scriptHomePath = asterixInstallerPath + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "transactionts" + File.separator + "scripts"; env.put("SCRIPT_HOME", scriptHomePath); TestsUtils.executeScript(pb, scriptHomePath + File.separator + "setup_teardown" + File.separator + "configure_and_validate.sh"); TestsUtils.executeScript(pb, scriptHomePath + File.separator + "setup_teardown" + File.separator + "stop_and_delete.sh"); }
From source file:Main.java
public static void unZipFolder(InputStream input, String outPathString) throws Exception { java.util.zip.ZipInputStream inZip = new java.util.zip.ZipInputStream(input); java.util.zip.ZipEntry zipEntry = null; String szName = ""; while ((zipEntry = inZip.getNextEntry()) != null) { szName = zipEntry.getName();//from w ww . j a v a2 s . c o m if (zipEntry.isDirectory()) { // get the folder name of the widget szName = szName.substring(0, szName.length() - 1); java.io.File folder = new java.io.File(outPathString + java.io.File.separator + szName); folder.mkdirs(); } else { java.io.File file = new java.io.File(outPathString + java.io.File.separator + szName); file.createNewFile(); // get the output stream of the file java.io.FileOutputStream out = new java.io.FileOutputStream(file); int len; byte[] buffer = new byte[1024]; // read (len) bytes into buffer while ((len = inZip.read(buffer)) != -1) { // write (len) byte from buffer at the position 0 out.write(buffer, 0, len); out.flush(); } out.close(); } } //end of while inZip.close(); }
From source file:Main.java
public static File getCacheDir(Context c) { File cacheDir = c.getExternalCacheDir(); if (null == cacheDir) cacheDir = c.getCacheDir();/* www .j av a 2 s . com*/ if (!cacheDir.exists()) cacheDir.mkdirs(); return cacheDir; }
From source file:Main.java
public static int checkFileStatus(String dirPath, String fileName, String suffix) { int fileStatus; String filePath = checkFilePath(dirPath, fileName, suffix); if (filePath == null) { return fileStatus = FILE_ERROR; }//from ww w. j a va2 s . co m try { File dirFile = new File(dirPath); if (!dirFile.exists()) { dirFile.mkdirs(); } File mFile = new File(filePath); if (!mFile.exists()) { fileStatus = FILE_CREATE; mFile.createNewFile(); } else { long size = mFile.length(); if (size > 0) { fileStatus = FILE_EXISTS; } else { fileStatus = FILE_EXISTS_NULL; } } } catch (IOException e) { e.printStackTrace(); return FILE_ERROR; } return fileStatus; }
From source file:Main.java
public static void saveImage(String imagePath, Bitmap bm) { if (bm == null || imagePath == null || "".equals(imagePath)) { return;//from w w w. ja v a 2 s. co m } File f = new File(imagePath); if (f.exists()) { return; } else { try { File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } f.createNewFile(); FileOutputStream fos; fos = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.close(); } catch (FileNotFoundException e) { f.delete(); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); f.delete(); } } }
From source file:Main.java
public static void unzipEPub(String inputZip, String destinationDirectory) throws IOException { int BUFFER = 2048; List zipFiles = new ArrayList(); File sourceZipFile = new File(inputZip); File unzipDestinationDirectory = new File(destinationDirectory); unzipDestinationDirectory.mkdir();/* w ww . java2 s .c om*/ ZipFile zipFile; zipFile = new ZipFile(sourceZipFile, ZipFile.OPEN_READ); Enumeration zipFileEntries = zipFile.entries(); // Process each entry while (zipFileEntries.hasMoreElements()) { ZipEntry entry = (ZipEntry) zipFileEntries.nextElement(); String currentEntry = entry.getName(); File destFile = new File(unzipDestinationDirectory, currentEntry); if (currentEntry.endsWith(".zip")) { zipFiles.add(destFile.getAbsolutePath()); } File destinationParent = destFile.getParentFile(); destinationParent.mkdirs(); if (!entry.isDirectory()) { BufferedInputStream is = new BufferedInputStream(zipFile.getInputStream(entry)); int currentByte; // buffer for writing file byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER); while ((currentByte = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, currentByte); } dest.flush(); dest.close(); is.close(); } } zipFile.close(); for (Iterator iter = zipFiles.iterator(); iter.hasNext();) { String zipName = (String) iter.next(); unzipEPub(zipName, destinationDirectory + File.separatorChar + zipName.substring(0, zipName.lastIndexOf(".zip"))); } }
From source file:cat.ogasoft.protocolizer.processor.CompilerPhase.java
public static void processCompiler(RoundEnvironment roundEnv) throws CompilerException { try {// w ww . j a va2s . com String protocPath = "src" + File.separatorChar + "cat" + File.separatorChar + "ogasoft" + File.separatorChar + "protocolizer" + File.separatorChar + "protoc"; DefaultExecutor de = new DefaultExecutor(); for (Element element : roundEnv.getElementsAnnotatedWith(ProtoFileV2.Compiler.class)) { ProtoFileV2.Compiler compiler = element.getAnnotation(ProtoFileV2.Compiler.class); if (compiler.compile()) { String base = protocPath.replace('.', File.separatorChar); File dst = new File(base); if (!dst.exists() && !dst.mkdirs()) { throw new Exception("Cann not be created directory " + dst.getAbsolutePath()); } File rootDirectori = new File(base); //Compile all the files in compiler.protoFilePaths() FileFilter filter = new FileFilter() { @Override public boolean accept(File pathname) { return pathname.getName().toLowerCase().endsWith(".proto"); } }; for (File protoc : rootDirectori.listFiles(filter)) { String target = base + File.separatorChar + protoc.getName(); LOG.info("\tCompiling " + target + "..."); CommandLine cmd = CommandLine.parse(compiler.command() + " --proto_path=" + protocPath + " " + compiler.language().option + "=src " + target); int result = de.execute(cmd); if (result != 0) { throw new CompilerException("HO ho... somthing went wrong, code: " + result); } LOG.info("\t" + target + " compiled"); } } } } catch (Exception e) { //Any exception is a CompilerException. throw new CompilerException(e.getMessage()); } }