List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:fr.inria.eventcloud.deployment.cli.launchers.EventCloudsManagementServiceDeployer.java
private static void downloadLibs(String libsUrl) throws IOException { libDirPath = System.getProperty("java.io.tmpdir") + File.separator + "eventcloud-libs"; File tmpLibDir = new File(libDirPath); tmpLibDir.mkdir(); File readme = new File(tmpLibDir, "README"); FileUtils.copyURLToFile(new URL(libsUrl + "README"), readme); String[] libNames = FileUtils.readFileToString(readme).split("\n"); for (String libName : libNames) { FileUtils.copyURLToFile(new URL(libsUrl + libName), new File(tmpLibDir, libName)); }/*from w w w .ja va 2 s .c o m*/ }
From source file:Main.java
private static File createFileOrDir(String path, String fileName, boolean isDir) { if (path.charAt(path.length() - 1) != '/') { path += '/'; }/* w w w . ja v a 2 s. co m*/ File file = new File(path + fileName); if (!isDir) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } else { file.mkdir(); } return file; }
From source file:com.l.notel.notel.org.redpin.android.util.ExceptionReporter.java
/** * Search for stack trace files.// w w w . ja v a 2 s .co m * * @return */ private static String[] searchForStackTraces() { if (stackTraceFileList != null) { return stackTraceFileList; } File dir = new File(E.FILES_PATH + "/"); // Try to create the files folder if it doesn't exist dir.mkdir(); // Filter for ".stacktrace" files FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { return name.endsWith(".stacktrace"); } }; return (stackTraceFileList = dir.list(filter)); }
From source file:org.cloudfoundry.client.lib.SampleProjects.java
private static File explodeTestApp(File file, TemporaryFolder temporaryFolder) throws IOException { File unpackDir = temporaryFolder.newFolder(file.getName()); if (unpackDir.exists()) { FileUtils.forceDelete(unpackDir); }/* w ww.ja va 2 s. c o m*/ unpackDir.mkdir(); ZipFile zipFile = new ZipFile(file); try { unpackZip(zipFile, unpackDir); } finally { zipFile.close(); } return unpackDir; }
From source file:IO.Files.java
/** * Returns true if the given file is successfully moved to the destination * folder//from ww w. j av a 2s . co m * * @param file source file * @param subFolderName the name of the subfolder to create and move the * file to * @return true if the given file is successfully moved to the destination * folder */ public static boolean MoveFileToSubFolder(File file, String subFolderName) { String filename = file.getName(); File destinationFolder = new File(file.getParent() + "\\" + subFolderName); String destinationFilePath = destinationFolder + "\\" + filename; if (!destinationFolder.exists()) { destinationFolder.mkdir(); } if (file.renameTo(new File(destinationFilePath))) { //System.out.println(String.format("File '%s' is moved successful to folder:\n%s\n", filename, destinationFolder)); return true; } else { //System.out.println(String.format("File '%s' is failed to move to folder: \n%s\n", filename, destinationFolder)); return false; } }
From source file:edu.osu.netmotifs.warswap.common.CreateDirectory.java
public static boolean createDir(String directoryPath) { boolean success = true; logger.debug("Enter path of directory to create"); // Creating new directory in Java, if it doesn't exists File directory = new File(directoryPath); if (directory.exists()) { logger.debug("Directory already exists ..."); } else {// w w w . j a va 2 s .c o m logger.debug("Directory not exists, creating now"); success = directory.mkdir(); if (success) { logger.debug("Successfully created new directory : " + directoryPath); } else { logger.error("Failed to create new directory: " + directoryPath); } } return success; }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * Compress files to *.zip.//from w w w . j a v a 2 s. c o m * @param fileName * file name to compress * @return compressed file. */ public static String compress(String fileName) { String targetFile = null; File sourceFile = new File(fileName); Vector<File> vector = getAllFiles(sourceFile); try { if (sourceFile.isDirectory()) { targetFile = fileName + ".zip"; } else { char ch = '.'; targetFile = fileName.substring(0, fileName.lastIndexOf(ch)) + ".zip"; } BufferedInputStream bis = null; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile)); ZipOutputStream zipos = new ZipOutputStream(bos); byte[] data = new byte[BUFFER]; if (vector.size() > 0) { for (int i = 0; i < vector.size(); i++) { File file = vector.get(i); zipos.putNextEntry(new ZipEntry(getEntryName(fileName, file))); bis = new BufferedInputStream(new FileInputStream(file)); int count; while ((count = bis.read(data, 0, BUFFER)) != -1) { zipos.write(data, 0, count); } bis.close(); zipos.closeEntry(); } zipos.close(); bos.close(); return targetFile; } else { File zipNullfile = new File(targetFile); zipNullfile.getParentFile().mkdirs(); zipNullfile.mkdir(); return zipNullfile.getAbsolutePath(); } } catch (IOException e) { LOG.error("[compress]", e); return "error"; } }
From source file:edu.cmu.lti.oaqa.annographix.solr.SolrEvalUtils.java
public static void saveEvalResults(String questionTemplate, String topicId, SolrRes[] results, ArrayList<String> allKeyWords, String docDirName, int maxNum) throws Exception { File docRootDir = new File(docDirName); if (!docRootDir.exists()) { if (!docRootDir.mkdir()) throw new Exception("Cannot create: " + docRootDir.getAbsolutePath()); }/* ww w . j a va2s .co m*/ String docDirPrefix = docDirName + "/" + topicId; File docDir = new File(docDirPrefix); if (!docDir.exists()) { if (!docDir.mkdir()) throw new Exception("Cannot create: " + docDir.getAbsolutePath()); } // Let's precompile replacement regexps Pattern[] replReg = new Pattern[allKeyWords.size()]; String[] replRepl = new String[allKeyWords.size()]; for (int i = 0; i < allKeyWords.size(); ++i) { replReg[i] = Pattern.compile("(^| )(" + allKeyWords.get(i) + ")( |$)", Pattern.CASE_INSENSITIVE); replRepl[i] = "$1<b>$2</b>$3"; } for (int docNum = 0; docNum < Math.min(results.length, maxNum); ++docNum) { String docId = results[docNum].mDocId; ArrayList<String> docText = results[docNum].mDocText; StringBuilder sb = new StringBuilder(); sb.append("<html><body><br>"); sb.append("<p><i>" + questionTemplate + "</i></p><hr><br>"); for (String s : docText) { for (int k = 0; k < replReg.length; ++k) { while (true) { /* * When words share a space, the replacement will not work in the first pass * Imagine you have * word1 word2 * And both words need to be replaced. In the first pass, only * word1 is replaced. */ String sNew = replReg[k].matcher(s).replaceAll(replRepl[k]); if (sNew.equals(s)) break; s = sNew; } } sb.append(s); sb.append("<br>"); } sb.append("</body></html>"); String text = sb.toString(); File df = new File(docDirPrefix + "/" + docId + ".html"); // Don't overwrite docs! if (!df.exists()) { try { FileUtils.write(df, text); } catch (IOException e) { throw new Exception("Cannot write to file: " + df.getAbsolutePath() + " reason: " + e); } } else { System.out.println(String.format("WARNING: ignoring already created document for topic %s docId %s", topicId, docId)); } } }
From source file:com.magic.util.FileUtil.java
public static String getPatchedFileName(String path, String fileName) throws IOException { // make sure the export directory exists if (UtilValidate.isNotEmpty(path)) { path = path.replaceAll("\\\\", "/"); File parentDir = new File(path); if (!parentDir.exists()) { if (!parentDir.mkdir()) { throw new IOException("Cannot create directory for path: " + path); }/* ww w .j a v a2 s. c om*/ } // build the filename with the path if (!path.endsWith("/")) { path = path + "/"; } if (fileName.startsWith("/")) { fileName = fileName.substring(1); } fileName = path + fileName; } return fileName; }
From source file:com.netflix.imfutility.itunes.metadata.film.FilmMetadataXmlProviderTest.java
@BeforeClass public static void setupAll() throws IOException { // create both working directory and logs folder. FileUtils.deleteDirectory(TemplateParameterContextCreator.getWorkingDir()); File workingDir = TemplateParameterContextCreator.getWorkingDir(); if (!workingDir.mkdir()) { throw new RuntimeException("Could not create a working dir within tmp folder"); }//from w w w . j av a 2 s . co m try { context = JAXBContext.newInstance(PackageType.class); } catch (JAXBException e) { throw new RuntimeException(e); } }