List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:Main.java
/** * Compress a String to a zip file that has only one entry like zipName * The name shouldn't have .zip//from w ww . j a v a 2s . c o m * * @param content * @param fName * @throws IOException */ public static void zipAContentAsFileName(String fName, String content, String charset) throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes(charset)); BufferedInputStream bis = new BufferedInputStream(bais); File f = new File(fName); File parentFile = f.getParentFile(); if (!parentFile.exists()) { parentFile.mkdirs(); } ZipOutputStream zf = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f + ".zip"))); ZipEntry entry = new ZipEntry(f.getName()); zf.putNextEntry(entry); byte[] barr = new byte[8192]; int len = 0; while ((len = bis.read(barr)) != -1) { zf.write(barr, 0, len); } zf.flush(); zf.close(); bis.close(); bais.close(); }
From source file:Main.java
public static File getDataFileSoPatchForInstall(Context base) { File dir = new File(base.getFilesDir().getAbsolutePath() + File.separator + "rocoolib" + File.separator); if (!dir.exists()) { dir.mkdirs(); }/*from w w w . j a va 2 s.c o m*/ return dir; }
From source file:Main.java
public static String prepareFilePathForVideoSaveWithDraftUri(Uri draftUri) { String draftPath = draftUri.getPath(); String draftMediaDirPath = draftPath.substring(0, draftPath.length() - 5); File draftMediaDir = new File(draftMediaDirPath); if (!draftMediaDir.exists()) { draftMediaDir.mkdirs(); }/*from w ww .j a va 2 s.c o m*/ String[] files = draftMediaDir.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { return filename.endsWith("-0.mp4") || filename.endsWith("-a.mp4"); } }); List<String> filePaths = Arrays.asList(files); Collections.sort(filePaths, new Comparator<String>() { @Override public int compare(String lhs, String rhs) { return rhs.compareTo(lhs); } }); if (filePaths.size() > 0) { for (String file : filePaths) { return new File(draftMediaDir, file.substring(0, file.length() - 6) + ".mp4").getAbsolutePath(); } } return new File(draftMediaDir, generateRandomFilename("mp4")).getAbsolutePath(); }
From source file:Main.java
/** * Reads the in_stream and extracts them to out_dir. * @param in_stream Input stream corresponding to the zip file. * @param out_dir Output directory for the zip file contents. * @throws IOException/*from w ww .java 2 s. c o m*/ */ public static void zipExtract(InputStream in_stream, File out_dir) throws IOException { if (!out_dir.exists()) { if (!out_dir.mkdirs()) { throw new IOException("Could not create output directory: " + out_dir.getAbsolutePath()); } } ZipInputStream zis = new ZipInputStream(in_stream); ZipEntry ze; byte[] buffer = new byte[BUFFER_SIZE]; int count; while ((ze = zis.getNextEntry()) != null) { if (ze.isDirectory()) { File fmd = new File(out_dir.getAbsolutePath() + "/" + ze.getName()); fmd.mkdirs(); continue; } FileOutputStream fout = new FileOutputStream(out_dir.getAbsolutePath() + "/" + ze.getName()); while ((count = zis.read(buffer)) != -1) { fout.write(buffer, 0, count); } fout.close(); zis.closeEntry(); } zis.close(); }
From source file:Main.java
public static void init(Context context) { voice_wechat_paths = new ArrayList<>(); voice_qq_paths = new ArrayList<>(); if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File dir = Environment.getExternalStorageDirectory(); File f = new File(dir + "/tencent/MicroMsg"); if (f.exists() && f.canRead() && f.isDirectory()) { File[] files = f.listFiles(); if (files == null || files.length == 0) { return; }//from ww w .java2 s. c o m for (File f0 : files) { if (f0.isDirectory() && f0.getName().length() > 24) { voice_wechat_paths.add(f0.getAbsolutePath() + "/voice2"); } } } File exportDir = new File(dir, "silkv3_mp3"); if (!exportDir.exists()) { exportDir.mkdirs(); } export_dir = exportDir.getAbsolutePath(); } }
From source file:Main.java
public static String saveFile(Context c, String filePath, String fileName, byte[] bytes) { String fileFullName = ""; FileOutputStream fos = null;/*from w ww .j a va 2 s . co m*/ String dateFolder = new SimpleDateFormat("yyyyMMdd", Locale.CHINA).format(new Date()); try { String suffix = ""; if (filePath == null || filePath.trim().length() == 0) { filePath = Environment.getExternalStorageDirectory() + "/tuiji/" + dateFolder + "/"; } File file = new File(filePath); if (!file.exists()) { file.mkdirs(); } File fullFile = new File(filePath, fileName + suffix); fileFullName = fullFile.getPath(); fos = new FileOutputStream(new File(filePath, fileName + suffix)); fos.write(bytes); } catch (Exception e) { fileFullName = ""; } finally { if (fos != null) { try { fos.close(); } catch (IOException e) { fileFullName = ""; } } } return fileFullName; }
From source file:br.edimarmanica.weir2.rule.type.RulesDataTypeController.java
/** * Persiste the datatype of each rule//from ww w .jav a2 s . c o m * * @param site */ public static void persiste(Site site) { Map<String, DataType> ruleType = new HashMap<>(); File dirInput = new File(Paths.PATH_INTRASITE + "/" + site.getPath() + "/extracted_values"); for (File rule : dirInput.listFiles()) { ruleType.put(rule.getName(), RuleDataType.getMostFrequentType(rule)); } File dirOutput = new File(Paths.PATH_WEIR_V2 + "/" + site.getPath()); dirOutput.mkdirs(); File file = new File(dirOutput.getAbsolutePath() + "/types.csv"); String[] HEADER = { "RULE", "TYPE" }; CSVFormat format = CSVFormat.EXCEL.withHeader(HEADER); try (Writer out = new FileWriter(file)) { try (CSVPrinter csvFilePrinter = new CSVPrinter(out, format)) { for (String rule : ruleType.keySet()) { List<String> dataRecord = new ArrayList<>(); dataRecord.add(rule); dataRecord.add(ruleType.get(rule).name()); csvFilePrinter.printRecord(dataRecord); } } } catch (IOException ex) { Logger.getLogger(RulesDataTypeController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.flowpowered.engine.render.DeployNatives.java
public static void deploy() throws Exception { final String osPath; final String[] nativeLibs; if (SystemUtils.IS_OS_WINDOWS) { nativeLibs = new String[] { "jinput-dx8_64.dll", "jinput-dx8.dll", "jinput-raw_64.dll", "jinput-raw.dll", "jinput-wintab.dll", "lwjgl.dll", "lwjgl64.dll", "OpenAL32.dll", "OpenAL64.dll" }; osPath = "windows/"; } else if (SystemUtils.IS_OS_MAC) { nativeLibs = new String[] { "libjinput-osx.jnilib", "liblwjgl.jnilib", "openal.dylib" }; osPath = "mac/"; } else if (SystemUtils.IS_OS_LINUX) { nativeLibs = new String[] { "liblwjgl.so", "liblwjgl64.so", "libopenal.so", "libopenal64.so", "libjinput-linux.so", "libjinput-linux64.so" }; osPath = "linux/"; } else {/* w w w . java 2 s.c o m*/ throw new IllegalStateException("Could not get lwjgl natives for OS \"" + SystemUtils.OS_NAME + "\"."); } final File nativesDir = new File("natives" + File.separator + osPath); nativesDir.mkdirs(); for (String nativeLib : nativeLibs) { final File nativeFile = new File(nativesDir, nativeLib); if (!nativeFile.exists()) { FileUtils.copyInputStreamToFile(DeployNatives.class.getResourceAsStream("/" + nativeLib), nativeFile); } } final String nativesPath = nativesDir.getAbsolutePath(); System.setProperty("org.lwjgl.librarypath", nativesPath); System.setProperty("net.java.games.input.librarypath", nativesPath); }
From source file:hudson.init.impl.InitialUserContent.java
@Initializer(after = JOB_LOADED) public static void init(Jenkins h) throws IOException { File userContentDir = new File(h.getRootDir(), "userContent"); if (!userContentDir.exists()) { userContentDir.mkdirs(); FileUtils.writeStringToFile(new File(userContentDir, "readme.txt"), Messages.Hudson_USER_CONTENT_README()); }/*from w w w .j a v a2s .com*/ }
From source file:Main.java
private static void initData(Activity activity) { mActivity = activity;/*from w w w . j a v a 2 s.co m*/ File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName"); if (!mFile.exists()) mFile.mkdirs(); mAvatar = new File(TEMP_IMG_PATH); if (mAvatar.exists()) mAvatar.delete(); mAvatarUri = Uri.fromFile(mAvatar); }