List of usage examples for java.io File getParent
public String getParent()
null
if this pathname does not name a parent directory. From source file:com.athena.peacock.common.core.util.ZipUtil.java
/** * <pre>// w w w.jav a2 s . c om * ? ? ? . * </pre> * @param baseDir * @param destFile * @return * @throws IOException * @throws ManifestException */ public static String compress(String baseDir, String destFile) throws IOException, ManifestException { Assert.notNull(baseDir, "baseDir cannot be null."); Project project = new Project(); File filesetDir = new File(baseDir); File archiveFile = null; Assert.isTrue(filesetDir.exists(), baseDir + " does not exist."); Assert.isTrue(filesetDir.isDirectory(), baseDir + " is not a directory."); if (StringUtils.isEmpty(destFile)) { archiveFile = new File(filesetDir.getParent(), new StringBuilder(filesetDir.getName()).append(".zip").toString()); } else { archiveFile = new File(destFile); } FileSet fileSet = new FileSet(); fileSet.setDir(filesetDir); fileSet.setProject(project); // project ? DirectoryScanner ? Excption? ?. Zip zip = new Zip(); zip.setProject(project); // project ? destFile Exception ?. zip.setDestfile(archiveFile); zip.add(fileSet); zip.execute(); return archiveFile.getAbsolutePath(); }
From source file:com.mgmtp.perfload.perfalyzer.util.IoUtilities.java
private static void extractEntry(final ZipFile zf, final ZipEntry entry, final File destDir) throws IOException { File file = new File(destDir, entry.getName()); if (entry.isDirectory()) { file.mkdirs();//from w w w.java 2s . c o m } else { new File(file.getParent()).mkdirs(); try (InputStream is = zf.getInputStream(entry); FileOutputStream os = new FileOutputStream(file)) { copy(Channels.newChannel(is), os.getChannel()); } // preserve modification time; must be set after the stream is closed file.setLastModified(entry.getTime()); } }
From source file:gr.abiss.calipso.util.AttachmentUtils.java
/** * @param file/* w w w. j a v a 2 s . com*/ * @throws IOException */ private static void ensureFileExists(File file) throws IOException { new File(file.getParent()).mkdirs(); file.createNewFile(); }
From source file:com.athena.chameleon.common.utils.ZipUtil.java
/** * <pre>//from www. jav a 2 s . c o m * ? ? ? . * </pre> * @param baseDir * @param destFile * @param type * @return * @throws IOException * @throws ManifestException */ public static boolean compress(String baseDir, String destFile, ArchiveType type) throws IOException, ManifestException { Assert.notNull(baseDir, "baseDir cannot be null."); Project project = new Project(); File filesetDir = new File(baseDir); File archiveFile = null; Assert.isTrue(filesetDir.exists(), baseDir + " does not exist."); Assert.isTrue(filesetDir.isDirectory(), baseDir + " is not a directory."); if (StringUtils.isEmpty(destFile)) { archiveFile = new File(filesetDir.getParent(), new StringBuilder(filesetDir.getName()).append(".").append(type.value()).toString()); } else { archiveFile = new File(destFile); } FileSet fileSet = new FileSet(); fileSet.setDir(filesetDir); fileSet.setProject(project); // project ? DirectoryScanner ? Excption? ?. Zip zip = new Zip(); zip.setProject(project); // project ? destFile Exception ?. zip.setDestfile(archiveFile); zip.add(fileSet); zip.execute(); return true; }
From source file:context.ui.misc.FileHandler.java
/** * * @param message/*from w w w . j av a 2 s . c o m*/ * @return */ public static FileData openFileChooser(String message) { FileChooser fileChooser = new FileChooser(); fileChooser.setTitle(message); fileChooser.setInitialDirectory(new File(getLastFileLocation())); final File selectedFile = fileChooser.showOpenDialog(ContextFXController.getStage()); if (selectedFile != null) { selectedFile.getAbsolutePath(); FileData file = new FileData(new SimpleStringProperty(selectedFile.getName()), selectedFile); setLastFileLocation(selectedFile.getParent()); return file; } else { System.out.println("Selected File is Null"); return null; } }
From source file:jp.terasoluna.fw.util.PropertyUtil.java
/** * ????? ??? ??????? ?????//from w ww . j a va2 s .co m * @param resource ??? * @param addFile ? * @return ???? */ private static String getPropertiesPath(String resource, String addFile) { File file = new File(resource); String dir = file.getParent(); if (dir != null) { StringBuilder dirBuf = new StringBuilder(); dirBuf.setLength(0); dirBuf.append(dir); dirBuf.append(File.separator); dir = dirBuf.toString(); } else { dir = ""; } StringBuilder retBuf = new StringBuilder(); retBuf.setLength(0); retBuf.append(dir); retBuf.append(addFile); return retBuf.toString(); }
From source file:com.taobao.android.builder.tools.BuildHelper.java
public static File doSign(File apkFile, DefaultSigningConfig signConfig) throws IOException, SigningException { if (null == signConfig) { return apkFile; }/*from ww w.j a v a2 s . co m*/ File signFile = new File(apkFile.getParent(), apkFile.getName().replace(".apk", "-signed.apk")); AtlasBuildContext.sBuilderAdapter.androidSigner.signFile(apkFile, signFile, signConfig); return signFile; }
From source file:helpers.Methods.java
/** * This method will store the remaining links to the LOGS/Links.csv *//* w w w . jav a 2s . c om*/ public static void makeLinksLogs() { FileWriter out = null; try { File inputDirectory = new File(Variables.inputFile); File outputFile = new File(checkDirectory(inputDirectory.getParent()) + File.separator + "Links.csv"); if (outputFile.getParentFile() != null) { outputFile.getParentFile().mkdirs(); } out = new FileWriter(outputFile); String tmp = ""; tmp = Variables.inputFileOutputFileName + "," + Variables.inputFileLinksColumnName + "\r\n"; out.write(tmp); //CSV Header for (WebDocument doc : getRemainingProfileLinks()) { doc.resetCounter(); tmp = doc.getOutputName() + ","; String url = doc.getNextUrl(); while (url != null) { tmp += url + Variables.inputFileLinksSeparator; url = doc.getNextUrl(); } //remove last separator //TODO Check the sustring works fine or not. //Error occured when all threads finished their work. tmp = tmp.substring(0, tmp.lastIndexOf(Variables.inputFileLinksSeparator)); out.write(tmp + "\r\n"); out.flush(); } out.close(); } catch (IOException ex) { Variables.logger.Log(Methods.class, Variables.LogType.Error, "Error in saving remaining links. Details:\r\n" + ex.getMessage()); } }
From source file:hivemall.xgboost.NativeLibLoader.java
private static void tryLoadNativeLib(final String userDefinedLib) { final File userDefinedLibFile = new File(userDefinedLib); if (!userDefinedLibFile.exists()) { logger.warn(userDefinedLib + " not found"); } else {/*ww w . j ava 2 s. c o m*/ try { File tempFile = createTempFileFromResource(userDefinedLibFile.getName(), new FileInputStream(userDefinedLibFile.getAbsolutePath())); logger.info("Copyed the user-defined native library as " + tempFile.getAbsolutePath()); addLibraryPath(tempFile.getParent()); } catch (Exception e) { // Simply ignore it here logger.warn(e.getMessage()); } } }
From source file:dynamicrefactoring.domain.xml.ExportImportUtilities.java
/** * Se encarga del proceso de exportacin de una refactorizacin dinmica. * //from w w w . j ava2 s .co m * @param destination * directorio a donde se quiere exportar la refactorizacin. * @param definition * ruta del fichero con la definicin de la refactorizacin. * @param createFolders * indica si los ficheros .class se copian en al carpeta raz o * si se genera la estructura de carpetas correspondiente. * @throws IOException * IOException. * @throws XMLRefactoringReaderException * XMLRefactoringReaderException. */ public static void exportRefactoring(String destination, String definition, boolean createFolders) throws IOException, XMLRefactoringReaderException { String folder = new File(definition).getParent(); FileManager.copyFolder(folder, destination); String refactoringName = FilenameUtils.getName(folder); DynamicRefactoringDefinition refact = new JDOMXMLRefactoringReaderImp() .getDynamicRefactoringDefinition(new File(definition)); FileManager.copyFile(new File(RefactoringConstants.DTD_PATH), new File(destination + "/" + refactoringName + "/"//$NON-NLS-1$ + new File(RefactoringConstants.DTD_PATH).getName())); for (RefactoringMechanismInstance mecanismo : refact.getAllMechanisms()) { String rule = PluginStringUtils.getMechanismFullyQualifiedName(mecanismo.getType(), mecanismo.getClassName()); final String className = mecanismo.getClassName(); //$NON-NLS-1$ String rulePath = rule.replace('.', File.separatorChar); File currentFile = new File( RefactoringConstants.REFACTORING_CLASSES_DIR + File.separatorChar + rulePath + ".class"); //$NON-NLS-1$ File destinationFile = new File( destination + File.separatorChar + refactoringName + File.separatorChar + className + ".class"); //$NON-NLS-1$ File destinationFolder = new File(destination); File newFolder = new File( destinationFolder.getParent() + File.separatorChar + new File(rulePath).getParent()); File newFile = new File(new File(destination).getParent() + File.separatorChar + rulePath + ".class"); //$NON-NLS-1$ // Si no existe el destino y si el actual if (!destinationFile.exists() && currentFile.exists()) { if (!createFolders) { FileManager.copyFile(currentFile, destinationFile); } else { if (!newFolder.exists()) { newFolder.mkdirs(); } FileManager.copyFile(currentFile, newFile); } } else { if (!currentFile.exists()) { // falta algn fichero .class necesario en esta // refactorizacin // En este caso se borra la carpeta generada en destino ya // que no estar completa FileManager.emptyDirectories(destination + File.separatorChar + refactoringName); FileManager.deleteDirectories(destination + File.separatorChar + refactoringName, true); throw new IOException(Messages.ExportImportUtilities_ClassesNotFound + currentFile.getPath()); } } } }