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
/** * Retorna el nombre del grupo de un caso de uso, a partir * del path de la pagina (preferentemente absoluto). * Ej: "UseCaseGroup"/*from ww w . ja v a 2 s. c om*/ */ public static String getGroupData(String path) { File original = new File(path); String useCaseName = original.getParentFile().getParentFile().getName(); return capitalize(useCaseName) + "Group"; }
From source file:ee.ioc.phon.android.inimesed.MyFileUtils.java
public static void saveFile(File f, String content) throws IOException { File dir = f.getParentFile(); if (!dir.exists() && !dir.mkdirs()) { throw new IOException("Cannot create directory: " + dir); }/*from w ww . j a v a2 s . c om*/ FileUtils.writeStringToFile(f, content, "UTF8"); }
From source file:Main.java
public static boolean createParentDir(File file) { boolean isMkdirs = true; if (!file.exists()) { File dir = file.getParentFile(); if (!dir.exists()) { isMkdirs = dir.mkdirs();/*from w w w. j ava 2 s . c o m*/ } } return isMkdirs; }
From source file:Main.java
public static boolean isAncestor(File ancestorCandidate, File childCandidtate) { File parent = childCandidtate; while (true) { parent = parent.getParentFile(); if (parent == null) { return false; }// w w w .ja v a 2 s . c om if (isSame(parent, ancestorCandidate)) { return true; } } }
From source file:io.pivotal.strepsirrhini.chaosloris.docs.MarkdownWriterResolver.java
private static void createDirectoriesIfNecessary(File outputFile) { File parent = outputFile.getParentFile(); if (!parent.isDirectory() && !parent.mkdirs()) { throw new IllegalStateException("Failed to create directory '" + parent + "'"); }//from www .j ava 2 s . c o m }
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; }/*from w w w . j a va 2 s . com*/ 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:jodtemplate.util.Utils.java
public static void createParentFolders(final File file) throws IOException { if (!file.getParentFile().exists()) { final boolean dirsCreated = file.getParentFile().mkdirs(); if (!dirsCreated) { throw new IOException(); }//ww w.j av a 2 s .co m } }
From source file:Main.java
private static final void copyInputStream(InputStream in, String fileName) throws FileNotFoundException { File file = new File(fileName); File parentFile = file.getParentFile(); parentFile.mkdirs();/*www . j a v a 2 s . co m*/ System.out.println("Creating parent directory... " + parentFile.getAbsolutePath()); byte[] buffer = new byte[1024]; FileOutputStream fos = new FileOutputStream(file); BufferedOutputStream out = new BufferedOutputStream(fos); int len; try { while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); } } catch (IOException ex) { } finally { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:Main.java
/** * author: liuxu/*from w w w. j a v a 2s. c o m*/ * save bitmap into file * @param bitmap the bitmap * @param path full path of the file * @param quality Hint to the compressor, 0-100. 0 meaning compress for * small size, 100 meaning compress for max quality. Some * formats, like PNG which is lossless, will ignore the * quality setting * @return true if success */ public static boolean saveBitmap(Bitmap bitmap, String path, int quality) { if (bitmap == null) { return false; } File file = new File(path); File parent = file.getParentFile(); if (parent != null && !parent.exists()) { if (!parent.mkdirs()) { //Log.e(TAG, "saveBitmap, mkdir for parent fail"); return false; } } try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); } catch (IOException e) { //Log.d(TAG, "saveBitmap fail", e); return false; } return true; }
From source file:Main.java
public static boolean createFile(File file) { if (file.isDirectory()) { file.mkdirs();/* w ww. ja v a2 s . c o m*/ } else if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } try { file.createNewFile(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } return true; }