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.ruesga.rview.TestUtils.java
public static File getRootDirectory() { File test = new File("").getAbsoluteFile(); if (test.getName().equals("rview")) { return test; }//w w w . java 2 s . co m if (test.getName().equals("app")) { return test.getParentFile(); } return test; }
From source file:de.thischwa.pmcms.tool.compression.Zip.java
/** * Method to extract all {@link ZipInfo}s into 'destDir'. Inner directory structure will be copied. * // w w w.jav a2 s. com * @param destDir * @param zipInfo * @param monitor must be initialized by the caller. * @throws IOException */ public static void extract(final File destDir, final ZipInfo zipInfo, final IProgressMonitor monitor) throws IOException { if (!destDir.exists()) destDir.mkdirs(); for (String key : zipInfo.getEntryKeys()) { ZipEntry entry = zipInfo.getEntry(key); InputStream in = zipInfo.getInputStream(entry); File entryDest = new File(destDir, entry.getName()); entryDest.getParentFile().mkdirs(); if (!entry.isDirectory()) { OutputStream out = new FileOutputStream(new File(destDir, entry.getName())); try { IOUtils.copy(in, out); out.flush(); if (monitor != null) monitor.worked(1); } finally { // cleanup IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } } } if (monitor != null) monitor.done(); }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * Compress files to *.zip./*w w w .ja va 2 s. co m*/ * @param fileName * file name to compress * @return compressed file. */ public static String compress(String fileName) { String targetFile = null; File sourceFile = new File(fileName); Vector<File> vector = getAllFiles(sourceFile); try { if (sourceFile.isDirectory()) { targetFile = fileName + ".zip"; } else { char ch = '.'; targetFile = fileName.substring(0, fileName.lastIndexOf(ch)) + ".zip"; } BufferedInputStream bis = null; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(targetFile)); ZipOutputStream zipos = new ZipOutputStream(bos); byte[] data = new byte[BUFFER]; if (vector.size() > 0) { for (int i = 0; i < vector.size(); i++) { File file = vector.get(i); zipos.putNextEntry(new ZipEntry(getEntryName(fileName, file))); bis = new BufferedInputStream(new FileInputStream(file)); int count; while ((count = bis.read(data, 0, BUFFER)) != -1) { zipos.write(data, 0, count); } bis.close(); zipos.closeEntry(); } zipos.close(); bos.close(); return targetFile; } else { File zipNullfile = new File(targetFile); zipNullfile.getParentFile().mkdirs(); zipNullfile.mkdir(); return zipNullfile.getAbsolutePath(); } } catch (IOException e) { LOG.error("[compress]", e); return "error"; } }
From source file:net.orpiske.sdm.lib.net.Downloader.java
/** * Setups the output file// w w w .j a v a2s . c o m * @param url file URL * @param overwrite whether to overwrite existent files * @return A new File object pointing to the output file * @throws MalformedURLException * @throws URISyntaxException * @throws IOException if unable to create the output directory, file or remove an * existent file */ private static File setupOutputFile(String url, boolean overwrite) throws MalformedURLException, URISyntaxException, IOException { String fileName = URLUtils.getFilename(url); String workDir = WorkdirUtils.getWorkDir(); String fullName = workDir + File.separator + fileName; File outputFile = new File(fullName); if (!outputFile.getParentFile().exists()) { if (!outputFile.getParentFile().mkdirs()) { throw new IOException("Unable to create output directory " + fullName); } } if (!outputFile.exists()) { if (!outputFile.createNewFile()) { throw new IOException("Unable to create file " + fullName); } } else { if (overwrite) { if (outputFile.delete()) { if (!outputFile.createNewFile()) { throw new IOException("Unable to create file " + fullName); } } else { throw new IOException("Unable to delete existing file " + fullName); } } else { logger.info("Destination file " + fullName + " already exists"); } } return outputFile; }
From source file:br.univali.ps.fuzzy.portugolFuzzyCorretor.control.FileController.java
public static String getCodigoPortugol() throws FileNotFoundException { JFileChooser fc = new JFileChooser(currentDirectory); FileNameExtensionFilter filter = new FileNameExtensionFilter("Portugol Code", "por", "txt"); fc.setFileFilter(filter);/*w w w. j a va 2 s.com*/ fc.setAcceptAllFileFilterUsed(false); File file = null; int returnVal = fc.showOpenDialog(null); if (returnVal == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); currentDirectory = file.getParentFile().getPath(); return formatarArquivoTexto(file); } return ""; }
From source file:com.adguard.compiler.PackageUtils.java
public static File createXpi(String makeXpiSh, File file, String xpiName) throws Exception { execute(makeXpiSh, file.getAbsolutePath()); File xpiFile = new File(file, xpiName + ".xpi"); File destXpiFile = new File(file.getParentFile(), file.getName() + ".xpi"); if (destXpiFile.exists()) { FileUtils.deleteQuietly(destXpiFile); }//from w w w.j a v a 2 s . c o m FileUtils.moveFile(xpiFile, destXpiFile); FileUtils.deleteQuietly(file); return destXpiFile; }
From source file:com.ibm.soatf.component.soap.builder.Wsdl.java
public static URL saveWsdl(URL wsdlUrl, File rootWsdl) { return SoapLegacyFacade.saveWsdl(wsdlUrl, rootWsdl.getName(), rootWsdl.getParentFile()); }
From source file:hu.juranyi.zsolt.jauthortagger.util.TestUtils.java
public static File exportResourceFile(String resFn, String outFn) { File outFile = new File(TEST_DIR, outFn); InputStream is = null;/*w w w . j av a 2s.c om*/ OutputStream os = null; try { File parent = outFile.getParentFile(); if (null != parent && !parent.exists()) { parent.mkdirs(); } is = resource(resFn); os = new FileOutputStream(outFile); IOUtils.copy(is, os); } catch (Exception e) { e.printStackTrace(); } finally { if (null != is) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (null != os) { try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } return outFile; }
From source file:info.magnolia.importexport.Bootstrapper.java
/** * Get the files to bootstrap. The method garantees that only one file is imported if it occures twice in the * bootstrap dir. The set is returned sorted, so that the execution fo the import will import the upper most nodes * first. This is done using the filelength. * * @return the sorted set/* ww w. j ava2 s . co m*/ */ private static SortedSet<File> getBootstrapFiles(String[] bootdirs, final String repositoryName, final BootstrapFilter filter) { SortedSet<File> xmlfileset = new TreeSet<File>(new BootstrapFilesComparator()); for (int j = 0; j < bootdirs.length; j++) { String bootdir = bootdirs[j]; File xmldir = new File(bootdir); if (!xmldir.exists() || !xmldir.isDirectory()) { continue; } @SuppressWarnings("unchecked") Collection<File> files = FileUtils.listFiles(xmldir, new IOFileFilter() { @Override public boolean accept(File file) { return accept(file.getParentFile(), file.getName()); } @Override public boolean accept(File dir, String name) { return name.startsWith(repositoryName + ".") && filter.accept(name) && (name.endsWith(DataTransporter.XML) || name.endsWith(DataTransporter.ZIP) || name.endsWith(DataTransporter.GZ) || name.endsWith(DataTransporter.PROPERTIES)); } }, FileFilterUtils.trueFileFilter()); xmlfileset.addAll(files); } return xmlfileset; }
From source file:org.jboss.as.test.integration.web.annotationsmodule.WebModuleDeploymentTestCase.java
public static void doSetup() throws Exception { File testModuleRoot = new File(getModulePath(), "org/jboss/test/webModule"); File file = testModuleRoot; while (!getModulePath().equals(file.getParentFile())) file = file.getParentFile();//from w ww . j a va 2s. c om deleteRecursively(file); createTestModule(testModuleRoot); }