List of usage examples for java.io File mkdir
public boolean mkdir()
From source file:de.nico.asura.Main.java
private static void checkDir() { File dir = new File(Environment.getExternalStorageDirectory() + "/" + localLoc + "/"); if (!dir.exists()) dir.mkdir(); }
From source file:com.intuit.tank.tools.debugger.PanelBuilder.java
public static File createWorkingDir(AgentDebuggerFrame frame, String baseUrl) { try {//from w w w .ja v a 2 s . c om File temp = File.createTempFile("temp", Long.toString(System.nanoTime())); temp.delete(); temp = new File(temp.getAbsolutePath() + ".d"); temp.mkdir(); workingDir = temp; // create settings.xml writeSettings(workingDir, getHeaders(baseUrl)); System.setProperty("WATS_PROPERTIES", workingDir.getAbsolutePath()); } catch (IOException e) { LOG.error("Error creating temp working dir: " + e); frame.showError("Error creating temp working dir: " + e); } return workingDir; }
From source file:de.lazyzero.kkMulticopterFlashTool.utils.Zip.java
public static File unzipFile(File zipFile, File file) { System.out.println("path to zipFile: " + zipFile.getPath()); System.out.println("file to extract: " + file.getPath()); String fileName = null;//from www. j ava2 s .com try { zipFile.mkdir(); BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile(zipFile); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); // System.out.println(entry.getName()); if (entry.getName().substring(entry.getName().indexOf("/") + 1).equals(file.getName())) { // if (entry.getName().contains(file.getName())){ System.out.println("firmware to extract found."); String tempFolder = System.getProperty("user.dir") + File.separatorChar + "tmp" + File.separatorChar; if (System.getProperty("os.name").toLowerCase().contains("mac")) { tempFolder = System.getProperty("user.home") + "/Library/Preferences/kkMulticopterFlashTool/"; } String newDir; if (entry.getName().indexOf("/") == -1) { newDir = zipFile.getName().substring(0, zipFile.getName().indexOf(".")); } else { newDir = entry.getName().substring(0, entry.getName().indexOf("/")); } String folder = tempFolder + newDir; System.out.println("Create folder: " + folder); if ((new File(folder).mkdir())) { System.out.println("Done."); ; } System.out.println("Extracting: " + entry); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[2048]; fileName = tempFolder + entry.getName(); FileOutputStream fos = new FileOutputStream(tempFolder + entry.getName()); dest = new BufferedOutputStream(fos, 2048); while ((count = is.read(data, 0, 2048)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); break; } } } catch (ZipException e) { zipFile.delete(); kk.err(Translatrix._("error.zipfileDamaged")); kk.err(Translatrix._("reportProblem")); } catch (Exception e) { e.printStackTrace(); } return new File(fileName); }
From source file:com.ruesga.rview.misc.CacheHelper.java
@SuppressWarnings("ResultOfMethodCallIgnored") public static File getAccountDiffCacheDir(Context context, Account account) { createAccountCacheDir(context, account); File cacheDir = new File(getAccountCacheDir(context, account), DIFF_CACHE_FOLDER); if (!cacheDir.exists()) { cacheDir.mkdir(); }/*from w w w . j a va2 s. com*/ return cacheDir; }
From source file:com.jada.browser.YuiImageBrowser.java
static public void customInit(String baseDir, SecurityManager securityManager, int maxsize) throws Exception { Logger.getLogger(YuiImageBrowser.class).info("customInit"); YuiImageBrowser.baseDir = baseDir;//from w w w. j a v a2 s .co m YuiImageBrowser.securityManager = securityManager; YuiImageBrowser.maxsize = maxsize; externalInit = true; File file = new File(baseDir); if (!file.exists()) { if (!file.mkdir()) { throw new Exception("Unable to create working directory"); } } }
From source file:com.xxg.jdeploy.util.FileUtil.java
/** * // w ww . j av a 2s. c o m * @param src * @param dest * @throws IOException */ public static void copyFolder(File src, File dest) throws IOException { if (src.isDirectory()) { if (!dest.exists()) { dest.mkdir(); } String files[] = src.list(); for (String file : files) { File srcFile = new File(src, file); File destFile = new File(dest, file); // copyFolder(srcFile, destFile); } } else { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } in.close(); out.close(); } }
From source file:abfab3d.shapejs.Project.java
private static void extractZip(String zipFile, String outputFolder, Map<String, String> sceneFiles, List<String> resources) { byte[] buffer = new byte[1024]; try {//from w ww. jav a 2s. c om //create output directory is not exists File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { // Ignore directories if (ze.isDirectory()) continue; String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); System.out.println("file unzip : " + newFile.getAbsoluteFile()); FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } // Save path to the script and parameters files if (fileName.endsWith(".json")) { sceneFiles.put("paramFile", newFile.getAbsolutePath()); } else if (fileName.endsWith(".js")) { sceneFiles.put("scriptFile", newFile.getAbsolutePath()); } else { resources.add(newFile.getAbsolutePath()); } fos.close(); ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:eu.stratosphere.nephele.io.compression.CompressionLoader.java
/** * Returns the path to the native libraries or <code>null</code> if an error occurred. * /*from w ww .ja v a 2 s . c om*/ * @param libraryClass * the name of this compression library's wrapper class including full package name * @return the path to the native libraries or <code>null</code> if an error occurred */ private static String getNativeLibraryPath(final String libraryClass) { final ClassLoader cl = ClassLoader.getSystemClassLoader(); if (cl == null) { LOG.error("Cannot find system class loader"); return null; } final String classLocation = libraryClass.replace('.', '/') + ".class"; if (LOG.isDebugEnabled()) { LOG.debug("Class location is " + classLocation); } final URL location = cl.getResource(classLocation); if (location == null) { LOG.error("Cannot determine location of CompressionLoader class"); return null; } final String locationString = location.toString(); if (locationString.contains(".jar!")) { // Class if inside of a deployed jar file // Create and return path to native library cache final String pathName = GlobalConfiguration .getString(ConfigConstants.TASK_MANAGER_TMP_DIR_KEY, ConfigConstants.DEFAULT_TASK_MANAGER_TMP_PATH) .split(File.pathSeparator)[0] + File.separator + NATIVELIBRARYCACHENAME; final File path = new File(pathName); if (!path.exists()) { if (!path.mkdir()) { LOG.error("Cannot create directory for native library cache."); return null; } } return pathName; } else { String result = ""; int pos = locationString.indexOf(classLocation); if (pos < 0) { LOG.error("Cannot find extract native path from class location"); return null; } result = locationString.substring(0, pos) + "META-INF/lib"; // Strip the file:/ scheme, it confuses the class loader if (result.startsWith("file:")) { result = result.substring(5); } return result; } }
From source file:gdt.data.entity.BaseHandler.java
/** * Create an empty database//from w w w. j a va2 s .c o m * @param entihome$ the path of the new database * @return return null if succeed or an error message otherwise. */ public static String createBlankDatabase(String entihome$) { try { System.out.println("BaseHandler:createBlankDatabase.entihome=" + entihome$); File entihome = new File(entihome$); if (!entihome.exists()) { entihome.mkdir(); } File propertyBase = new File(entihome$ + "/" + Entigrator.PROPERTY_BASE + "/data/"); if (!propertyBase.exists()) propertyBase.mkdirs(); File propertyMap = new File(entihome$ + "/" + Entigrator.PROPERTY_MAP + "/data/"); if (!propertyMap.exists()) propertyMap.mkdirs(); File entityBase = new File(entihome$ + "/" + Entigrator.PROPERTY_BASE + "/data/"); if (!entityBase.exists()) entityBase.mkdirs(); Entigrator entigrator = new Entigrator(new String[] { entihome$ }); String[] sa = entigrator.indx_listEntities("label", "Icons"); Sack folder = null; if (sa == null) { folder = entigrator.ent_new("folder", "Icons", Entigrator.ICONS); folder.putAttribute(new Core(null, "icon", "folder.png")); entigrator.save(folder); folder = entigrator.ent_assignProperty(folder, "folder", folder.getProperty("label")); } File folderHome = new File(entihome$ + "/" + Entigrator.ICONS); if (!folderHome.exists()) folderHome.mkdir(); Sack dependencies = entigrator.ent_new("folder", "Dependencies", Entigrator.DEPENDENCIES); dependencies.putAttribute(new Core(null, "icon", "folder.png")); entigrator.save(dependencies); folder = entigrator.ent_assignProperty(folder, "folder", folder.getProperty("label")); folderHome = new File(entihome$ + "/" + Entigrator.DEPENDENCIES); if (!folderHome.exists()) folderHome.mkdir(); System.out.println("BaseHandler:createBlankDatabase:1"); InputStream is = ExtensionHandler.class.getResourceAsStream("commons-codec-1.10.jar"); if (is == null) System.out.println("BaseHandler:createBlankDatabase:cannot get input stream"); else { System.out.println("BaseHandler:createBlankDatabase:found input stream"); File out = new File(entihome$ + "/" + Entigrator.DEPENDENCIES + "/commons-codec-1.10.jar"); FileOutputStream fos = new FileOutputStream(out); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { fos.write(b, 0, bytesRead); } fos.close(); is.close(); } is = ExtensionHandler.class.getResourceAsStream("commons-compress-1.10.jar"); if (is == null) System.out.println("BaseHandler:createBlankDatabase:cannot get input stream"); else { System.out.println("BaseHandler:createBlankDatabase:found input stream"); File out = new File(entihome$ + "/" + Entigrator.DEPENDENCIES + "/commons-compress-1.10.jar"); FileOutputStream fos = new FileOutputStream(out); byte[] b = new byte[1024]; int bytesRead = 0; while ((bytesRead = is.read(b)) != -1) { fos.write(b, 0, bytesRead); } fos.close(); is.close(); } return null; } catch (Exception e) { Logger.getLogger(BaseHandler.class.getName()).severe(e.toString()); return e.toString(); } }
From source file:fredboat.audio.queue.MusicPersistenceHandler.java
public static void handlePreShutdown(int code) { File dir = new File("music_persistence"); if (!dir.exists()) { boolean created = dir.mkdir(); if (!created) { log.error("Failed to create music persistence directory"); return; }/* w w w.j av a 2 s . co m*/ } Map<Long, GuildPlayer> reg = PlayerRegistry.getRegistry(); boolean isUpdate = code == ExitCodes.EXIT_CODE_UPDATE; boolean isRestart = code == ExitCodes.EXIT_CODE_RESTART; for (long gId : reg.keySet()) { try { GuildPlayer player = reg.get(gId); if (!player.isPlaying()) { continue;//Nothing to see here } String msg; if (isUpdate) { msg = I18n.get(player.getGuild()).getString("shutdownUpdating"); } else if (isRestart) { msg = I18n.get(player.getGuild()).getString("shutdownRestarting"); } else { msg = I18n.get(player.getGuild()).getString("shutdownIndef"); } TextChannel activeTextChannel = player.getActiveTextChannel(); if (activeTextChannel != null) { CentralMessaging.sendMessage(activeTextChannel, msg); } JSONObject data = new JSONObject(); data.put("vc", player.getCurrentVoiceChannel().getId()); data.put("tc", activeTextChannel != null ? activeTextChannel.getId() : ""); data.put("isPaused", player.isPaused()); data.put("volume", Float.toString(player.getVolume())); data.put("repeatMode", player.getRepeatMode()); data.put("shuffle", player.isShuffle()); if (player.getPlayingTrack() != null) { data.put("position", player.getPosition()); } ArrayList<JSONObject> identifiers = new ArrayList<>(); for (AudioTrackContext atc : player.getRemainingTracks()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); AbstractPlayer.getPlayerManager().encodeTrack(new MessageOutput(baos), atc.getTrack()); JSONObject ident = new JSONObject() .put("message", Base64.encodeBase64String(baos.toByteArray())) .put("user", atc.getUserId()); if (atc instanceof SplitAudioTrackContext) { JSONObject split = new JSONObject(); SplitAudioTrackContext c = (SplitAudioTrackContext) atc; split.put("title", c.getEffectiveTitle()).put("startPos", c.getStartPosition()) .put("endPos", c.getStartPosition() + c.getEffectiveDuration()); ident.put("split", split); } identifiers.add(ident); } data.put("sources", identifiers); try { FileUtils.writeStringToFile(new File(dir, Long.toString(gId)), data.toString(), Charset.forName("UTF-8")); } catch (IOException ex) { if (activeTextChannel != null) { CentralMessaging.sendMessage(activeTextChannel, MessageFormat.format( I18n.get(player.getGuild()).getString("shutdownPersistenceFail"), ex.getMessage())); } } } catch (Exception ex) { log.error("Error when saving persistence file", ex); } } }