List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:com.jeffthefate.stacktrace.ExceptionHandler.java
/** * Search for stack trace files.//from w ww . ja va 2s . com * @return */ private static String[] searchForStackTraces() { if (stackTraceFileList != null) return stackTraceFileList; File dir = new File(G.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:bammerbom.ultimatecore.bukkit.resources.classes.ErrorLogger.java
public static void log(Throwable t, String s) { String time = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss-SSS").format(Calendar.getInstance().getTime()); File dir = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors"); if (!dir.exists()) { dir.mkdir(); }//from w w w . j a v a 2 s . co m File file = new File(Bukkit.getPluginManager().getPlugin("UltimateCore").getDataFolder() + "/Errors", time + ".txt"); if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); } } FileWriter outFile; try { outFile = new FileWriter(file); } catch (IOException e) { e.printStackTrace(); return; } PrintWriter out = new PrintWriter(outFile); out.println("======================================="); out.println("UltimateCore has run into an error "); out.println("Please report your error on dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket"); out.println("Bukkit version: " + Bukkit.getServer().getVersion()); out.println("UltimateCore version: " + r.getUC().getDescription().getVersion()); out.println("Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins())); out.println("Java version: " + System.getProperty("java.version")); out.println("OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version")); out.println("Time: " + time); out.println("Error message: " + t.getMessage()); out.println("UltimateCore message: " + s); out.println("======================================="); out.println("Stacktrace: \n" + ExceptionUtils.getStackTrace(t)); out.println("======================================="); out.close(); try { outFile.close(); } catch (IOException e) { e.printStackTrace(); } // Bukkit.getConsoleSender().sendMessage(" "); r.log(ChatColor.DARK_RED + "========================================================="); r.log(ChatColor.RED + "UltimateCore has run into an error "); r.log(ChatColor.RED + "Please report your error on "); r.log(ChatColor.YELLOW + "http://dev.bukkit.org/bukkit-plugins/ultimate_core/create-ticket"); r.log(ChatColor.RED + "Include the file: "); r.log(ChatColor.YELLOW + "plugins/UltimateCore/Errors/" + time + ".txt "); /*r.log(ChatColor.RED + "Bukkit version: " + Bukkit.getServer().getVersion()); r.log(ChatColor.RED + "UltimateCore version: " + Bukkit.getPluginManager().getPlugin("UltimateCore").getDescription().getVersion()); r.log(ChatColor.RED + "Plugins loaded (" + Bukkit.getPluginManager().getPlugins().length + "): " + Arrays.asList(Bukkit.getPluginManager().getPlugins())); r.log(ChatColor.RED + "Java version: " + System.getProperty("java.version")); r.log(ChatColor.RED + "OS info: " + System.getProperty("os.arch") + ", " + System.getProperty("os.name") + ", " + System.getProperty("os.version")); r.log(ChatColor.RED + "Error message: " + t.getMessage()); r.log(ChatColor.RED + "UltimateCore message: " + s);*/ r.log(ChatColor.DARK_RED + "========================================================="); if (t instanceof Exception) { r.log(ChatColor.RED + "Stacktrace: "); t.printStackTrace(); r.log(ChatColor.DARK_RED + "========================================================="); } Bukkit.getConsoleSender().sendMessage(" "); }
From source file:com.googlecode.t7mp.util.ZipUtil.java
public static void unzip(InputStream warInputStream, File destination) { try {/*from w ww. jav a 2 s .c o m*/ ZipArchiveInputStream in = null; try { in = new ZipArchiveInputStream(warInputStream); ZipArchiveEntry entry = null; while ((entry = in.getNextZipEntry()) != null) { File outfile = new File(destination.getCanonicalPath() + "/" + entry.getName()); outfile.getParentFile().mkdirs(); if (entry.isDirectory()) { outfile.mkdir(); continue; } OutputStream o = new FileOutputStream(outfile); try { IOUtils.copy(in, o); } finally { o.close(); } } } finally { if (in != null) { in.close(); } } warInputStream.close(); } catch (FileNotFoundException e) { throw new TomcatSetupException(e.getMessage(), e); } catch (IOException e) { throw new TomcatSetupException(e.getMessage(), e); } }
From source file:cn.mdict.utils.IOUtil.java
public static boolean createDir(String dir) { File dirFile = new File(dir); return dirFile.mkdir(); }
From source file:co.cask.cdap.internal.app.runtime.LocalizationUtils.java
private static void unpack(File archive, File targetDir) throws IOException { if (!targetDir.exists()) { //noinspection ResultOfMethodCallIgnored targetDir.mkdir(); }//from www .j av a2 s . c om String extension = Files.getFileExtension(archive.getPath()).toLowerCase(); switch (extension) { case "zip": case "jar": BundleJarUtil.unJar(Locations.toLocation(archive), targetDir); break; case "gz": // gz is not recommended for archiving multiple files together. So we only support .tar.gz Preconditions.checkArgument(archive.getName().endsWith(".tar.gz"), "'.gz' format is not supported for " + "archiving multiple files. Please use 'zip', 'jar', '.tar.gz', 'tgz' or 'tar'."); untargz(archive, targetDir); break; case "tgz": untargz(archive, targetDir); break; case "tar": untar(archive, targetDir); break; default: throw new IllegalArgumentException( String.format("Unsupported compression type '%s'. Only 'zip', 'jar', " + "'tar.gz', 'tgz' and 'tar' are supported.", extension)); } }
From source file:org.meshpoint.anode.util.ModuleUtils.java
public static File unpack(File moduleResource, String moduleName, ModuleType modType) throws IOException { /* create temp dir to unpack; assume no hash collision */ String tmpDirName = moduleName + '-' + String.valueOf(counter++) + "-tmp"; File result = new File(resourceDir, tmpDirName); if (!result.isDirectory() && !result.mkdir()) throw new IOException("Unable to create tmp directory to unpack: " + result.toString()); if (modType.unpacker != null) { modType.unpacker.unpack(moduleResource, result); } else {/*w ww. j ava 2 s . c o m*/ Log.v(TAG, "ModuleUtils.unpack(): aborting (internal error)"); result = null; } return result; }
From source file:com.googlecode.jsonschema2pojo.integration.util.CodeGenerationHelper.java
public static File createTemporaryOutputFolder() { String tempDirectoryName = System.getProperty("java.io.tmpdir"); String outputDirectoryName = tempDirectoryName + File.separator + UUID.randomUUID().toString(); final File outputDirectory = new File(outputDirectoryName); try {/*ww w . j a v a2 s. c o m*/ outputDirectory.mkdir(); } finally { deleteOnExit(outputDirectory); } return outputDirectory; }
From source file:alluxio.AlluxioTestDirectory.java
/** * Creates the Alluxio testing directory and attempts to delete old files from the previous one. * * @return the testing directory/* w w w.j a va2s. c o m*/ */ private static File createTestingDirectory() { final File tmpDir = new File(System.getProperty("java.io.tmpdir"), "alluxio-tests"); if (tmpDir.exists()) { cleanUpOldFiles(tmpDir); } if (!tmpDir.exists()) { if (!tmpDir.mkdir()) { throw new RuntimeException("Failed to create testing directory " + tmpDir.getAbsolutePath()); } } return tmpDir; }
From source file:Main.java
public static void copyFolder(AssetManager assetManager, String source, String target) { // "Name" is the name of your folder! String[] files = null;/*from ww w . ja v a 2s. co m*/ String state = Environment.getExternalStorageState(); if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media // Checking file on assets subfolder try { files = assetManager.list(source); } catch (IOException e) { Log.e("ERROR", "Failed to get asset file list.", e); } // Analyzing all file on assets subfolder for (String filename : files) { InputStream in = null; OutputStream out = null; // First: checking if there is already a target folder File folder = new File(target); boolean success = true; if (!folder.exists()) { success = folder.mkdir(); } if (success) { // Moving all the files on external SD String sourceFile = source + "/" + filename; String targetFile = folder.getAbsolutePath() + "/" + filename; try { in = assetManager.open(sourceFile); out = new FileOutputStream(targetFile); /*Log.i("WEBVIEW", Environment.getExternalStorageDirectory() + "/yourTargetFolder/" + name + "/" + filename);*/ copyFile(in, out); in.close(); in = null; out.flush(); out.close(); out = null; } catch (IOException e) { try { assetManager.list(sourceFile); } catch (IOException f) { Log.e("ERROR", "Failed to copy asset file: " + filename, f); continue; } copyFolder(assetManager, sourceFile, targetFile); } } else { // Do something else on failure } } } else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media } else { // Something else is wrong. It may be one of many other states, but // all we need // is to know is we can neither read nor write } }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.SaveModelUtils.java
private static void copyToTargetLocation(File source, File destination) throws IOException { if (source.isDirectory()) { if (!destination.exists()) { destination.mkdir(); }//ww w . j a v a2s. c om for (String file : source.list()) { File src = new File(source, file); File dest = new File(destination, file); copyToTargetLocation(src, dest); } } else { copySingleFile(source, destination); } }