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.huawei.streaming.cql.CQLTestCommons.java
/** * /*from w w w . j a v a2s . c om*/ * * @param f * @param values * @throws IOException ? */ public static void appendToFile(File f, String values) throws IOException { if (!f.exists()) { if (!f.getParentFile().exists()) { f.getParentFile().mkdirs(); } LOG.warn("file " + f.getPath() + " does not exist! will create it."); if (!f.createNewFile()) { LOG.error("failed to create file " + f.getPath()); return; } } if (f.isDirectory()) { LOG.error("file " + f.getPath() + " is a directory!"); } FileUtils.write(f, values, CHARSET, true); }
From source file:it.geosolutions.jaiext.JAIEXTInitializationTest.java
@BeforeClass public static void setup() throws FileNotFoundException, IOException { final File inputJAIFile = TestData.file(JAIEXTInitializationTest.class, "META-INF" + File.separator + "registryFile2.jaiext"); newJAIFile = new File(inputJAIFile.getParentFile().getParentFile().getParentFile().getParentFile() .getParentFile().getParentFile(), "META-INF" + File.separator + "registryFile.jaiext"); FileUtils.copyFile(inputJAIFile, newJAIFile); }
From source file:com.adguard.compiler.PackageUtils.java
public static File createZip(String makeZipSh, File file) throws Exception { execute(makeZipSh, file.getAbsolutePath()); File zipFile = new File(file, file.getName() + ".zip"); File destZipFile = new File(file.getParentFile(), zipFile.getName()); FileUtils.deleteQuietly(destZipFile); FileUtils.moveFile(zipFile, destZipFile); return destZipFile; }
From source file:Main.java
public static void addFilesRecursive(List<String> files, File location, FilenameFilter filter) { if (!location.exists()) { return;/* w ww . j av a 2 s . c om*/ } if (!location.isDirectory()) { if (filter.accept(location.getParentFile(), location.getName())) { files.add(location.getAbsolutePath()); } } // we are in a directory => add all files matching filter and then // recursively add all files in subdirectories File[] tmp = location.listFiles(filter); if (tmp != null) { for (File file : tmp) { files.add(file.getAbsolutePath()); } } File[] dirs = location.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory(); } }); if (dirs == null) { return; } for (File dir : dirs) { addFilesRecursive(files, dir, filter); } }
From source file:com.autentia.common.util.FileSystemUtils.java
private static void copyFileLowLevel(File source, File target) throws FileNotFoundException, IOException { target.getParentFile().mkdirs(); final InputStream is = new FileInputStream(source); final OutputStream os = new FileOutputStream(target); final byte[] buffer = new byte[65536]; // 64 KBytes de buffer int c;//from www .j a v a 2s. com while ((c = is.read(buffer)) != -1) { os.write(buffer, 0, c); } os.close(); is.close(); }
From source file:com.ibm.watson.developer_cloud.professor_languo.ingestion.indexing.StackExchangeThreadSerializer.java
/** * Serialize a StackExchangeThread into a binary file * //w w w . j a va2s .c o m * @param threadToSerialize - The StackExchangeThread to be serialized * @return the path(relative to the resource folder) of the serialized binary file * @throws IngestionException */ public static String serializeThreadToBinFile(StackExchangeThread threadToSerialize, String dirPath) throws IngestionException { String binFileName = threadToSerialize.getId() + StackExchangeConstants.BIN_FILE_SUFFIX; try { String binFilePath = dirPath + binFileName; File serFile = new File(binFilePath); if (serFile.getParentFile() != null) serFile.getParentFile().mkdirs(); if (!serFile.exists()) serFile.createNewFile(); OutputStream binOut = new FileOutputStream(serFile); ObjectOutputStream out = new ObjectOutputStream(binOut); out.writeObject(threadToSerialize); out.close(); binOut.close(); } catch (IOException e) { throw new IngestionException(e); } return binFileName; }
From source file:com.dexels.navajo.tipi.dev.server.appmanager.impl.UnsignJarTask.java
public static void downloadDepencency(Dependency d, File repoDir, File destinationFolder, List<String> extraHeaders) throws IOException { String assembledName = d.getFileNameWithVersion(); String tmpAssembledFile = "tmp_" + assembledName; String tmpAssembled = d.getArtifactId() + "_" + d.getVersion(); File dest = new File(destinationFolder, tmpAssembledFile); FileOutputStream fos = new FileOutputStream(dest); File ff = d.getFilePathForDependency(repoDir); File parent = ff.getParentFile(); if (!parent.exists()) { parent.mkdirs();/*w w w . j a v a 2 s . co m*/ } logger.info("Downloading: " + ff.getAbsolutePath()); ZipUtils.copyResource(fos, d.getUrl().openStream()); File tmpDir = new File(destinationFolder, tmpAssembled); tmpDir.mkdirs(); ZipUtils.unzip(dest, tmpDir); cleanSigningData(tmpDir, extraHeaders); File destinationZip = new File(destinationFolder, assembledName); ZipUtils.zipAll(tmpDir, destinationZip); FileUtils.copyFileToDirectory(destinationZip, parent); FileUtils.deleteDirectory(tmpDir); dest.delete(); }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * get file entry name according to base * @param base/*from w ww. j a va 2 s . c om*/ * base to split the total file * @param file * file to get the entry * @return entry name. */ private static String getEntryName(String base, File file) { File baseFile = new File(base); String filename = file.getPath(); if (baseFile.getParentFile().getParentFile() == null) { return filename.substring(baseFile.getParent().length()); } // d:/file1 /file2/text.txt /*d:/file1/text.txt*/ return filename.substring(baseFile.getParent().length() + 1); }
From source file:com.jdom.util.properties.PropertiesUtil.java
public static void writePropertiesFile(Properties properties, File outputFile) throws IllegalArgumentException { OutputStream os = null;// w w w. j av a 2 s. co m try { outputFile.delete(); outputFile.getParentFile().mkdirs(); outputFile.createNewFile(); os = new FileOutputStream(outputFile); properties.store(os, ""); } catch (IOException e) { throw new IllegalArgumentException(e); } finally { IOUtils.closeQuietly(os); } }
From source file:com.github.blindpirate.gogradle.common.GoSourceCodeFilter.java
private static boolean isVendorDirectoryOfProject(File dir, File projectDir) { return VENDOR_DIRECTORY.equals(dir.getName()) && projectDir.equals(dir.getParentFile()); }