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.adguard.compiler.PackageUtils.java
public static File createCrx(String makeCrxSh, File file, File certificate) throws Exception { execute(makeCrxSh, file.getAbsolutePath(), certificate.getAbsolutePath()); File crxFile = new File(file, file.getName() + ".crx"); File destCrxFile = new File(file.getParentFile(), crxFile.getName()); FileUtils.deleteQuietly(destCrxFile); FileUtils.moveFile(crxFile, destCrxFile); return destCrxFile; }
From source file:com.chinamobile.bcbsp.fault.tools.HdfsOperater.java
/** * download file from hdfs// ww w .j ava2s . c o m * @param srcfilePath * source file path to download * @param destFilePath * destination path to download to. */ public static void downloadHdfs(String srcfilePath, String destFilePath) { try { Configuration conf = new Configuration(); // FileSystem fs = FileSystem.get(URI.create(srcfilePath), conf); // FSDataInputStream hdfsInStream = fs.open(new Path(srcfilePath)); BSPFileSystem bspfs = new BSPFileSystemImpl(URI.create(srcfilePath), conf); BSPFSDataInputStream hdfsInStream = new BSPFSDataInputStreamImpl(bspfs, new BSPHdfsImpl().newPath(srcfilePath)); File dstFile = new File(destFilePath); if (!dstFile.getParentFile().exists()) { dstFile.getParentFile().mkdirs(); } OutputStream out = new FileOutputStream(destFilePath); byte[] ioBuffer = new byte[1024]; int readLen = hdfsInStream.read(ioBuffer); while (-1 != readLen) { out.write(ioBuffer, 0, readLen); readLen = hdfsInStream.read(ioBuffer); } out.close(); // hdfsInStream.close(); hdfsInStream.hdfsInStreamclose(); bspfs.close(); } catch (FileNotFoundException e) { //LOG.error("[downloadHdfs]", e); throw new RuntimeException("[downloadHdfs]", e); } catch (IOException e) { //LOG.error("[downloadHdfs]", e); throw new RuntimeException("[downloadHdfs]", e); } }
From source file:com.massabot.codesender.utils.SettingsFactory.java
/** * Convert legacy property file to JSON, move files from top level setting directory to UGS * settings directory.//from www. j av a2s. c o m */ private static void migrateOldSettings() { File newSettingsDir = getSettingsDirectory(); File oldSettingDir = newSettingsDir.getParentFile(); File oldPropertyFile = new File(oldSettingDir, PROPERTIES_FILENAME); File oldJsonFile = new File(oldSettingDir, JSON_FILENAME); // Convert property file in old location to json file in new location. if (oldPropertyFile.exists()) { try { Settings out = new Settings(); // logger.log(Level.INFO, "{0}: {1}", new // Object[]{Localization.getString("settings.log.location"), settingsFile}); logger.log(Level.INFO, "Log location: {0}", oldPropertyFile.getAbsolutePath()); Properties properties = new Properties(); properties.load(new FileInputStream(oldPropertyFile)); out.setLastOpenedFilename(properties.getProperty("last.dir", System.getProperty(USER_HOME))); out.setPort(properties.getProperty("port", "")); out.setPortRate(properties.getProperty("port.rate", "9600")); out.setManualModeEnabled(Boolean.valueOf(properties.getProperty("manualMode.enabled", FALSE))); out.setManualModeStepSize(Double.valueOf(properties.getProperty("manualMode.stepsize", "1"))); out.setScrollWindowEnabled(Boolean.valueOf(properties.getProperty("scrollWindow.enabled", "true"))); out.setVerboseOutputEnabled( Boolean.valueOf(properties.getProperty("verboseOutput.enabled", FALSE))); out.setFirmwareVersion(properties.getProperty("firmwareVersion", "GRBL")); out.setSingleStepMode(Boolean.valueOf(properties.getProperty("singleStepMode", FALSE))); out.setStatusUpdatesEnabled( Boolean.valueOf(properties.getProperty("statusUpdatesEnabled", "true"))); out.setStatusUpdateRate(Integer.valueOf(properties.getProperty("statusUpdateRate", "200"))); out.setDisplayStateColor(Boolean.valueOf(properties.getProperty("displayStateColor", "true"))); out.updateMacro(1, null, null, properties.getProperty("customGcode1", "G0 X0 Y0;")); out.updateMacro(2, null, null, properties.getProperty("customGcode2", "G0 G91 X10;G0 G91 Y10;")); out.updateMacro(3, null, null, properties.getProperty("customGcode3", "")); out.updateMacro(4, null, null, properties.getProperty("customGcode4", "")); out.updateMacro(5, null, null, properties.getProperty("customGcode5", "")); out.setLanguage(properties.getProperty("language", "en_US")); saveSettings(out); // Delete the old settings file if it exists. oldPropertyFile.delete(); } catch (IOException ex) { Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex); } } // Move old json file from old location to new location. else if (oldJsonFile.exists()) { try { // If the new file doesn't exist, move the old one. if (!getSettingsFile().exists()) { FileUtils.moveFile(oldJsonFile, getSettingsFile()); } // Delete the old settings file if it exists. oldJsonFile.delete(); } catch (IOException ex) { Logger.getLogger(SettingsFactory.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:com.lightbox.android.bitmap.BitmapLoader.java
private static Bitmap getBitmapFromNetwork(BitmapSource bitmapSource, BitmapSource.Type type, Config config) { Bitmap bitmap = null;// ww w . j av a 2s. c o m URI uri = bitmapSource.getUri(type); if (uri != null) { FileOutputStream fos = null; try { File file = new File(bitmapSource.getAbsoluteFileName(type)); // Ensure that the directory exist file.getParentFile().mkdirs(); HttpResponse httpResponse = HttpHelper.getInstance().call(HttpMethod.GET, uri, null); fos = new FileOutputStream(file); IOUtils.copy(httpResponse.getEntity().getContent(), fos); bitmap = BitmapCache.getInstance().getFromDisk(bitmapSource.getAbsoluteFileName(type), config) .getData(); } catch (IOException e) { DebugLog.d("", e.getMessage()); // Return null } finally { IOUtils.closeQuietly(fos); } } return bitmap; }
From source file:Main.java
public static void unCompress(String zipPath, String toPath) throws IOException { File zipfile = new File(zipPath); if (!zipfile.exists()) return;//from w w w .j a v a 2s . c om if (!toPath.endsWith("/")) toPath += "/"; File destFile = new File(toPath); if (!destFile.exists()) destFile.mkdirs(); ZipInputStream zis = new ZipInputStream(new FileInputStream(zipfile)); ZipEntry entry = null; try { while ((entry = zis.getNextEntry()) != null) { if (entry.isDirectory()) { File file = new File(toPath + entry.getName() + "/"); file.mkdirs(); } else { File file = new File(toPath + entry.getName()); if (!file.getParentFile().exists()) file.getParentFile().mkdirs(); FileOutputStream fos = null; try { fos = new FileOutputStream(file); byte buf[] = new byte[1024]; int len = -1; while ((len = zis.read(buf, 0, 1024)) != -1) { fos.write(buf, 0, len); } } finally { if (fos != null) { try { fos.close(); } catch (Exception e) { } } } } } } finally { zis.close(); } }
From source file:com.cip.crane.agent.utils.FileExtractUtils.java
public static File unBzip(final File inputFile) throws FileNotFoundException, IOException { return unBzip(inputFile, inputFile.getParentFile()); }
From source file:com.cip.crane.agent.utils.FileExtractUtils.java
public static File unGzip(final File inputFile) throws FileNotFoundException, IOException { return unGzip(inputFile, inputFile.getParentFile()); }
From source file:io.treefarm.plugins.haxe.utils.HaxelibHelper.java
public static File getHaxelibDirectoryForArtifactAndInitialize(String artifactId, String version, Logger logger) {/*from ww w. jav a 2 s. c om*/ File haxelibDirectory = getHaxelibDirectoryForArtifact(artifactId, version); if (haxelibDirectory != null) { File currentFile = new File(haxelibDirectory.getParentFile(), ".current"); if (!currentFile.exists()) { try { currentFile.createNewFile(); } catch (IOException e) { logger.error("Unable to create pointer for '" + artifactId + "' haxelib: " + e); // todo: throw exception!! } } } return haxelibDirectory; }
From source file:com.iggroup.oss.restdoclet.doclet.util.DocletUtils.java
/** * Gets the file containing the documentation of a class. * /*w w w. j a v a 2 s . com*/ * @param classDoc the Java documentation object of the class. * @return the file containing documentation. */ public static File documentationFile(final ClassDoc classDoc) { final StringBuffer path = new StringBuffer(); path.append(classDoc.qualifiedName().replace('.', File.separatorChar)); if (isController(classDoc)) { path.append(Controller.FILE_SUFFIX); } else { path.append(".class.xml"); } final File doc = new File(path.toString()); doc.getParentFile().mkdirs(); return doc; }
From source file:com.compomics.pladipus.core.control.util.ZipUtils.java
/** * Zips an entire folder in one go/*from w w w.j av a 2s . co m*/ * * @param input the original folder * @param output the destination zip file */ static public void zipFolder(File inputFolder, File zipFile) throws UnspecifiedPladipusException, IOException { if (zipFile.exists()) { zipFile.delete(); } zipFile.getParentFile().mkdirs(); zipFile.createNewFile(); try (FileOutputStream fileWriter = new FileOutputStream(zipFile); ZipOutputStream zip = new ZipOutputStream(fileWriter)) { addFolderToZip("", inputFolder.getAbsolutePath(), zip); zip.flush(); } }