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
/** * check for a parent directory// ww w . j a v a2 s . c om * @param file instance to check * @return True if the parent directory's File instance exists, otherwise false */ public static boolean hasParent(File file) { if (file.getParentFile() == null) return false; return file.getParentFile().exists(); }
From source file:Main.java
/** * Check if current record's parent is identically with the binary storage persistence configured-root-location. * * @param record/* ww w.j a va 2 s .com*/ * @return boolean true in case parent location is identically with root; false otherwise. */ private static boolean isRecordParentRoot(final File record) { return record.getParentFile().equals(_root); }
From source file:Main.java
public static void saveImage(String path, Bitmap bitmap) throws IOException { File file = new File(path); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs();/* w w w .j a v a2 s. co m*/ } FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos); fos.flush(); fos.close(); }
From source file:Main.java
public static void createFile(String filePath) throws IOException { File file = new File(filePath); File parent = file.getParentFile(); if (!parent.exists()) { parent.mkdirs();//from w ww.j a v a 2 s. c o m } file.createNewFile(); }
From source file:Main.java
public static FileOutputStream getFileOutputStream(String filePath) throws IOException { FileOutputStream out;/*from w ww .j av a 2 s . c o m*/ File file = new File(filePath); if (file.getParentFile().exists()) { file.getParentFile().delete(); } file.getParentFile().mkdirs(); file.createNewFile(); out = new FileOutputStream(file); return out; }
From source file:Main.java
public static boolean createEmptyFile(String path, long size) throws IOException { File file = new File(path); File parent = file.getParentFile(); parent.mkdirs();// w w w . ja va 2 s .c o m RandomAccessFile raf = new RandomAccessFile(file, "rw"); raf.setLength(size); raf.close(); return true; }
From source file:Main.java
public static File createFile(File destDir, String filename) { File file = new File(destDir, filename); File parent = file.getParentFile(); if (parent != null) parent.mkdirs();/*from ww w .ja v a 2 s. c o m*/ return file; }
From source file:Main.java
public static void writeFile(File file, String string) throws IOException { file.getParentFile().mkdirs(); DataOutputStream dout = new DataOutputStream(new FileOutputStream(file)); dout.write(string.getBytes());/* w w w .j a v a 2 s . c om*/ dout.close(); }
From source file:Main.java
public static boolean createEmptyFile(String path, long size) throws IOException { File file = new File(path); File parent = file.getParentFile(); parent.mkdirs();//from w w w . j av a 2 s . c om RandomAccessFile raf = null; raf = new RandomAccessFile(file, "rw"); raf.setLength(size); raf.close(); return true; }
From source file:Main.java
public static void dirCreate(File dir) { if (!dir.exists()) { dirCreate(dir.getParentFile()); dir.mkdir();// w ww .j a v a 2 s . c om } }