List of usage examples for java.io File getParentFile
public File getParentFile()
null
if this pathname does not name a parent directory. From source file:Main.java
public static File getLocalPath(Context context) { if (context == null) return null; File tmp = context.getFilesDir(); if (tmp != null) return tmp.getParentFile(); return null;//from www. j a v a2 s .com }
From source file:Main.java
public static void deleteFilesStartingWith(String string) { File specificFile = new File(string); File pFile = specificFile.getParentFile(); if (pFile != null) { for (File f : pFile.listFiles()) { if (f.getName().startsWith(specificFile.getName())) { f.delete();//from w w w . ja v a2s . c o m } } } }
From source file:Main.java
private static File getTempFile(Context context) { File imageFile = new File(context.getExternalCacheDir(), TEMP_IMAGE_NAME); imageFile.getParentFile().mkdirs(); return imageFile; }
From source file:Main.java
public static boolean createFile(String filename) { final File file = new File(filename); final File pf = file.getParentFile(); if (!pf.exists()) { pf.mkdirs();/*from w w w.java 2 s.c o m*/ } if (!file.exists()) { try { file.createNewFile(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; }
From source file:net.pickapack.net.IOHelper.java
/** * Extract the resource in the specified path. * * @param path the path to the resource//from www .j a v a2 s. c om */ public static void extractResource(String path) { File file = new File(path); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } try { IOUtils.copy(IOHelper.class.getResourceAsStream("/" + path), new FileOutputStream(path)); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static void dumpHprof(String path) { try {//from w w w . j ava 2 s. c o m String name = getDate() + OOM_SUFFIX; path = path + File.separator + name; File file = path != null ? new File(path) : null; if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); Debug.dumpHprofData(path); } catch (Throwable t) { t.printStackTrace(); } }
From source file:Main.java
public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception { InputStream in = new ByteArrayInputStream(bytes); File destFile = new File(filePath); if (!destFile.getParentFile().exists()) { destFile.getParentFile().mkdirs(); }/* ww w . j ava2 s . co m*/ destFile.createNewFile(); OutputStream out = new FileOutputStream(destFile); byte[] cache = new byte[CACHE_SIZE]; int nRead = 0; while ((nRead = in.read(cache)) != -1) { out.write(cache, 0, nRead); out.flush(); } out.close(); in.close(); }
From source file:Main.java
/** * Return a file with the given filename creating the necessary directories * if not present.// ww w .j av a 2 s.c om * * @param filename * The file * @return The created File instance */ public static File createFile(File destDir, String filename) { File file = new File(destDir, filename); File parent = file.getParentFile(); if (parent != null) parent.mkdirs(); return file; }
From source file:Main.java
/** * Prepares the destination directory by creating directories if needed * @param destination The destination directory * @throws IOException//from ww w . j a v a 2 s.co m */ public static void prepareDestination(File destination) throws IOException { File parent = destination.getParentFile(); if (!parent.exists()) { if (!parent.mkdirs()) { throw new IOException("Unable to create destination directory: " + parent.getPath()); } } }
From source file:Main.java
public static File touch(String fullFilePath) throws IOException { if (fullFilePath == null) { return null; }//from w w w . j ava2s .c o m File file = new File(fullFilePath); file.getParentFile().mkdirs(); if (!file.exists()) file.createNewFile(); return file; }