List of usage examples for java.io File mkdirs
public boolean mkdirs()
From source file:cereal.examples.thrift.ThriftPersonTest.java
@BeforeClass public static void start() throws IOException, InterruptedException { File target = new File(System.getProperty("user.dir") + "/target"); assertTrue(target.exists());//w w w . j av a 2s . c o m assertTrue(target.isDirectory()); File macParent = new File(target, "minicluster"); macParent.mkdirs(); File macDir = new File(macParent, ThriftPersonTest.class.getName()); if (macDir.exists()) { FileUtils.deleteQuietly(macDir); } MiniAccumuloConfig cfg = new MiniAccumuloConfig(macDir, PASSWORD); cfg.setNumTservers(1); mac = new MiniAccumuloCluster(cfg); mac.start(); }
From source file:Main.java
public static boolean copyFile(final File srcFile, final File saveFile) { File parentFile = saveFile.getParentFile(); if (!parentFile.exists()) { if (!parentFile.mkdirs()) return false; }// w w w .j a va 2 s . c om BufferedInputStream inputStream = null; BufferedOutputStream outputStream = null; try { inputStream = new BufferedInputStream(new FileInputStream(srcFile)); outputStream = new BufferedOutputStream(new FileOutputStream(saveFile)); byte[] buffer = new byte[1024 * 4]; int len; while ((len = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, len); } outputStream.flush(); } catch (IOException e) { e.printStackTrace(); return false; } finally { close(inputStream, outputStream); } return true; }
From source file:com.r573.enfili.common.io.file.FileHelper.java
/** * 0: dir not created because it already exists 1: dir created -1: dir needs * to be created, but failed//from w ww .ja v a 2 s. c om * * @param dir * @return */ public static int mkdirIfNotExists(File dir) { if (!dir.exists()) { if (dir.mkdirs()) { return 1; } else { return -1; } } else { return 0; } }
From source file:Main.java
public static File getSaveFolder(String folderName) { File file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + File.separator + folderName + File.separator); file.mkdirs(); return file;//from w w w . j a v a 2 s .c o m }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath); File dir = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!dir.exists()) { dir.mkdirs(); }/*from w ww . ja va 2 s .c o m*/ file.createNewFile(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.sequence.evaluation.GenerateCrossDomainCVReport.java
/** * Merges id2outcome files from sub-folders with cross-domain and creates a new folder * with overall results/* w ww . java2s . com*/ * * @param folder folder * @throws java.io.IOException */ public static void aggregateDomainResults(File folder, String subDirPrefix, final String taskFolderSubText, String outputFolderName) throws IOException { // list all sub-folders File[] folders = folder.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && pathname.getName().contains(taskFolderSubText); } }); if (folders.length == 0) { throw new IllegalArgumentException("No sub-folders 'SVMHMMTestTask*' found in " + folder); } // write to a file File outFolder = new File(folder, outputFolderName); File output = new File(outFolder, subDirPrefix); output.mkdirs(); File outCsv = new File(output, TOKEN_LEVEL_PREDICTIONS_CSV); CSVPrinter csvPrinter = new CSVPrinter(new FileWriter(outCsv), SVMHMMUtils.CSV_FORMAT); csvPrinter.printComment(SVMHMMUtils.CSV_COMMENT); ConfusionMatrix cm = new ConfusionMatrix(); for (File domain : folders) { File tokenLevelPredictionsCsv = new File(domain, subDirPrefix + "/" + TOKEN_LEVEL_PREDICTIONS_CSV); if (!tokenLevelPredictionsCsv.exists()) { throw new IllegalArgumentException( "Cannot locate tokenLevelPredictions.csv: " + tokenLevelPredictionsCsv); } CSVParser csvParser = new CSVParser(new FileReader(tokenLevelPredictionsCsv), CSVFormat.DEFAULT.withCommentMarker('#')); for (CSVRecord csvRecord : csvParser) { // copy record csvPrinter.printRecord(csvRecord); // update confusion matrix cm.increaseValue(csvRecord.get(0), csvRecord.get(1)); } } // write to file FileUtils.writeStringToFile(new File(outFolder, "confusionMatrix.txt"), cm.toString() + "\n" + cm.printNiceResults() + "\n" + cm.printLabelPrecRecFm() + "\n" + cm.printClassDistributionGold()); // write csv IOUtils.closeQuietly(csvPrinter); }
From source file:Main.java
public static Properties loadPropertyInstance(String filePath, String fileName) { try {/*ww w . j a v a 2 s. c o m*/ File d = new File(filePath); if (!d.exists()) { d.mkdirs(); } File f = new File(d, fileName); if (!f.exists()) { f.createNewFile(); } Properties p = new Properties(); InputStream is = new FileInputStream(f); p.load(is); is.close(); return p; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:Main.java
private static File getExternalCacheDir(Context context) { File dataDir = new File(new File(Environment.getExternalStorageDirectory(), "Android"), "data"); File appCacheDir = new File(new File(dataDir, context.getPackageName()), "cache"); if (!appCacheDir.exists()) { if (!appCacheDir.mkdirs()) { //L.w("Unable to create external cache directory"); return null; }// w ww.j a va 2s . c o m try { new File(appCacheDir, ".nomedia").createNewFile(); } catch (IOException e) { //L.i("Can't create \".nomedia\" file in application external cache directory"); return null; } } return appCacheDir; }
From source file:Main.java
public static boolean writeFile(byte[] buffer, String folder, String fileName) { boolean writeSucc = false; boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); String folderPath = ""; if (sdCardExist) { folderPath = Environment.getExternalStorageDirectory() + File.separator + folder + File.separator; } else {/* w w w . j a v a 2 s. co m*/ writeSucc = false; } File fileDir = new File(folderPath); if (!fileDir.exists()) { fileDir.mkdirs(); } File file = new File(folderPath + fileName); FileOutputStream out = null; try { out = new FileOutputStream(file); out.write(buffer); writeSucc = true; } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } return writeSucc; }
From source file:Main.java
public static void unzip(InputStream fin, String targetPath, Context context) throws IOException { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fin)); try {/*w w w .j av a 2 s.co m*/ ZipEntry zipEntry; int count; byte[] buffer = new byte[8192]; while ((zipEntry = zis.getNextEntry()) != null) { File file = new File(targetPath, zipEntry.getName()); File dir = zipEntry.isDirectory() ? file : file.getParentFile(); if (!dir.isDirectory() && !dir.mkdirs()) { throw new FileNotFoundException("Failed to get directory: " + dir.getAbsolutePath()); } if (zipEntry.isDirectory()) { continue; } FileOutputStream fout = new FileOutputStream(file); try { while ((count = zis.read(buffer)) != -1) fout.write(buffer, 0, count); } finally { fout.close(); } Log.d("TEST", "Unzipped " + file.getAbsolutePath()); } } finally { zis.close(); } }