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.oprisnik.semdroid.utils.FileUtils.java
public static void writeObjectToFile(Object object, File file) throws IOException { if (!file.exists()) { file.getParentFile().mkdirs(); }//www. j av a 2 s .c o m ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.writeObject(object); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:Main.java
public static File getRelativeFile(File baseFile, File fileToRelativize) throws IOException { if (baseFile.isFile()) { baseFile = baseFile.getParentFile(); }//from w w w . j av a2s. co m return new File(getRelativeFileInternal(baseFile.getCanonicalFile(), fileToRelativize.getCanonicalFile())); }
From source file:ar.com.init.agros.reporting.ReportExporter.java
public static void exportReportPlainXLS(JasperPrint jp, String path) throws JRException, FileNotFoundException, IOException { // JRXlsExporter exporter = new JRXlsExporter(); JExcelApiExporter exporter = new JExcelApiExporter(); File outputFile = new File(path); File parentFile = outputFile.getParentFile(); if (parentFile != null) { parentFile.mkdirs();//from ww w . j ava 2 s .c om } FileOutputStream fos = new FileOutputStream(outputFile); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jp); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fos); exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE, Boolean.TRUE); exporter.exportReport(); fos.close(); logger.info("Report exported: " + path); }
From source file:azkaban.project.DirectoryFlowLoaderTest.java
private static File decompressTarBZ2(InputStream is) throws IOException { File outputDir = Files.createTempDir(); try (TarArchiveInputStream tais = new TarArchiveInputStream(new BZip2CompressorInputStream(is))) { TarArchiveEntry entry;/* ww w . j av a2s. co m*/ while ((entry = tais.getNextTarEntry()) != null) { if (entry.isDirectory()) { continue; } File outputFile = new File(outputDir, entry.getName()); File parent = outputFile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } try (FileOutputStream os = new FileOutputStream(outputFile)) { IOUtils.copy(tais, os); } } return outputDir; } }
From source file:com.eucalyptus.gen2ools.TemplateGenerator.java
private static void writeTemplate(VelocityContext context, String templateName, File outFile) { if (!outFile.getParentFile().exists()) { outFile.getParentFile().mkdirs(); }// w w w.j a va 2 s. com Template template = null; try { template = Velocity.getTemplate(templateName); FileWriter out = new FileWriter(outFile); template.merge(context, out); out.flush(); out.close(); } catch (ResourceNotFoundException ex) { // couldn't find the template LOG.error(ex, ex); } catch (ParseErrorException ex) { // syntax error: problem parsing the template LOG.error(ex, ex); } catch (MethodInvocationException ex) { // something invoked in the template // threw an exception LOG.error(ex, ex); } catch (IOException ex) { LOG.error(ex, ex); } }
From source file:ee.ria.xroad.signer.certmanager.FileBasedOcspCache.java
private static void createIntermediateDirectories(File file) throws IOException { File path = file.getParentFile(); if (!path.exists() && !path.mkdirs()) { throw new IOException("Could not create path " + path); }/*from ww w.j a v a 2 s . c o m*/ }
From source file:Main.java
public static boolean deletePlaintextFiles(File instanceXml) { // NOTE: assume the directory containing the instanceXml contains ONLY // files related to this one instance. File instanceDir = instanceXml.getParentFile(); boolean allSuccessful = true; // encrypt files that do not end with ".enc", and do not start with "."; // ignore directories File[] allFiles = instanceDir.listFiles(); for (File f : allFiles) { if (f.equals(instanceXml)) continue; // don't touch instance file if (f.isDirectory()) continue; // don't handle directories if (!f.getName().endsWith(".enc")) { // not an encrypted file -- delete it! allSuccessful = allSuccessful & f.delete(); // DO NOT // short-circuit }/*from w w w. ja va 2s .com*/ } return allSuccessful; }
From source file:com.grillecube.common.utils.JSONHelper.java
public static void writeJSONObjectToFile(File file, JSONObject json) { try {/*from ww w.j a v a 2s . co m*/ file.getParentFile().mkdirs(); FileWriter writer = new FileWriter(file); writer.write(json.toString()); writer.flush(); writer.close(); } catch (Exception e) { return; } }
From source file:hu.juranyi.zsolt.jauthortagger.util.TestUtils.java
public static File createEmptyFile(String fn) { File outFile = new File(TEST_DIR, fn); FileWriter w = null;/* ww w. j a v a2 s . c o m*/ try { File parent = outFile.getParentFile(); if (null != parent && !parent.exists()) { parent.mkdirs(); } w = new FileWriter(outFile); } catch (IOException e) { e.printStackTrace(); } finally { if (null != w) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } } return outFile; }
From source file:de.micromata.genome.util.runtime.Log4JInitializer.java
/** * Try to find a log4j-dev.properies file. * * @param log4jfile the file for the log4j settings * @return the file//www . jav a2 s . c o m */ private static File findDevFile(File log4jfile) { File dir = log4jfile.getParentFile(); String name = log4jfile.getName(); int lidx = name.lastIndexOf('.'); if (lidx == -1) { return null; } String nname = name.substring(0, lidx) + "-dev" + name.substring(lidx); File nf = new File(dir, nname); if (nf.exists() == true && nf.canRead() == true) { return nf; } return null; }