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:com.starit.diamond.utils.AppNameUtils.java
public static String[] getAllAppNames(String[] excludes) { File classpath = getClasspath(); File deployDir = classpath.getParentFile(); List<String> appNames = new LinkedList<String>(); for (String suffix : SUFFIXS) { File[] files = listFiles(deployDir, suffix, excludes); addFilesToAppNames(files, appNames, suffix); }// w w w . ja v a2 s .c o m return appNames.toArray(new String[appNames.size()]); }
From source file:Main.java
public static void copyCompletely(URI input, URI output) throws IOException { try {/*from www.ja v a2 s . co m*/ InputStream in = null; try { File f = new File(input); if (f.exists()) in = new FileInputStream(f); } catch (Exception notAFile) { } File out = new File(output); File dir = out.getParentFile(); dir.mkdirs(); if (in == null) in = input.toURL().openStream(); copyCompletely(in, new FileOutputStream(out)); } catch (IllegalArgumentException e) { throw new IOException("Cannot copy to " + output); } }
From source file:Main.java
public static File findParentDir(File file, String fileKey) { if (fileKey.equals(file.getName())) { return file; } else if (file.getParentFile() != null) { return findParentDir(file.getParentFile(), fileKey); } else {/* ww w .ja v a2s .c om*/ return file.getParentFile(); } }
From source file:com.orange.ocara.tools.AssetsHelper.java
/** * Copy the asset at the specified path to this app's data directory. If the * asset is a directory, its contents are also copied. */// w ww. j a v a 2 s. c o m public static void copyAsset(AssetManager assetManager, String rootPath, String path, File targetFolder) throws IOException { String fullPath = StringUtils.isEmpty(path) ? rootPath : rootPath + File.separator + path; // If we have a directory, we make it and recurse. If a file, we copy its // contents. try { String[] contents = assetManager.list(fullPath); // The documentation suggests that list throws an IOException, but doesn't // say under what conditions. It'd be nice if it did so when the path was // to a file. That doesn't appear to be the case. If the returned array is // null or has 0 length, we assume the path is to a file. This means empty // directories will get turned into files. if (contents == null || contents.length == 0) { throw new IOException(); } // Recurse on the contents. for (String entry : contents) { String newPath = StringUtils.isEmpty(path) ? entry : path + File.separator + entry; copyAsset(assetManager, rootPath, newPath, targetFolder); } } catch (IOException e) { File file = new File(targetFolder, path); if (file.getParentFile() != null) { file.getParentFile().mkdirs(); } FileUtils.copyInputStreamToFile(assetManager.open(fullPath), file); } }
From source file:Main.java
public static String extractAppNameFromPath(File path) { if (path == null) { return null; }//from w ww . j av a2 s. com File parent = path.getParentFile(); File odkDir = new File(getOdkFolder()); while (parent != null && !parent.equals(odkDir)) { path = parent; parent = path.getParentFile(); } if (parent == null) { return null; } else { return path.getName(); } }
From source file:Main.java
/** * kudos: http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically) * @param zipFile// www. ja v a2 s . co m * @param destinationDirectory */ public static void unZip(String zipFile, String destinationDirectory) { try { FileInputStream fin = new FileInputStream(zipFile); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { Log.v("Decompress", "Unzipping " + ze.getName()); String destinationPath = destinationDirectory + File.separator + ze.getName(); if (ze.isDirectory()) { dirChecker(destinationPath); } else { FileOutputStream fout; try { File outputFile = new File(destinationPath); if (!outputFile.getParentFile().exists()) { dirChecker(outputFile.getParentFile().getPath()); } fout = new FileOutputStream(destinationPath); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } catch (Exception e) { // ok for now. Log.v("Decompress", "Error: " + e.getMessage()); } } } zin.close(); } catch (Exception e) { Log.e("Decompress", "unzip", e); } }
From source file:Main.java
private static File findPomRoot(File file) { if (file.isDirectory() && new File(file, "pom.xml").exists()) { return file; }/* www. j a v a2 s. com*/ if (file.getParentFile() != null) { return findPomRoot(file.getParentFile()); } return null; }
From source file:com.beginner.core.utils.FileUpload.java
/** * ?upload/*from w w w.ja v a2 s . c o m*/ * @param in ?InputStream * @param dir ?? * @param realName ?? * @throws IOException IO */ private static String copyFile(InputStream in, String dir, String realName) throws IOException { File file = new File(dir, realName); if (!file.exists()) { if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } file.createNewFile(); } FileUtils.copyInputStreamToFile(in, file); return realName; }
From source file:Main.java
public static void unzip(File zipFile, File targetDirectory) throws IOException { ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFile))); try {// w w w . j av a 2 s . c om ZipEntry ze; int count; byte[] buffer = new byte[8192]; while ((ze = zis.getNextEntry()) != null) { File file = new File(targetDirectory, ze.getName()); File dir = ze.isDirectory() ? file : file.getParentFile(); if (!dir.isDirectory() && !dir.mkdirs()) throw new FileNotFoundException("Failed to ensure directory: " + dir.getAbsolutePath()); if (ze.isDirectory()) continue; FileOutputStream fout = new FileOutputStream(file); try { while ((count = zis.read(buffer)) != -1) fout.write(buffer, 0, count); } finally { fout.close(); } } } finally { zis.close(); } }
From source file:neembuu.uploader.zip.generator.utils.NUFileUtils.java
/** * Get the nth parent directory of the given file. * * @param file The file.//from w w w .j av a 2s . co m * @param n The nth directory. * @return Returns the nth parent directory. */ public static File getNthParentDirectory(File file, int n) { if (n > 1) { return getNthParentDirectory(file.getParentFile(), n - 1); } return file.getParentFile(); }