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:msec.org.TarUtil.java
public static void dearchive(File srcFile) throws Exception { String basePath = srcFile.getParent(); dearchive(srcFile, new File(basePath)); }
From source file:com.ibm.soatf.tool.FileSystem.java
public static String getRelativePath(File file) { try {//from w w w. ja v a 2s .c o m final String filePath = file.getCanonicalPath(); final String testPath = file.getParentFile().getParentFile().getParent(); if (filePath.startsWith(testPath)) { return filePath.substring(testPath.length() + 1); } else { return null; } } catch (IOException e) { ; } return file.getAbsolutePath(); }
From source file:IO.Files.java
/** * Returns true if the given file is successfully moved to the destination * folder/*from w w w . j ava 2 s.c o m*/ * * @param file source file * @param subFolderName the name of the subfolder to create and move the * file to * @return true if the given file is successfully moved to the destination * folder */ public static boolean MoveFileToSubFolder(File file, String subFolderName) { String filename = file.getName(); File destinationFolder = new File(file.getParent() + "\\" + subFolderName); String destinationFilePath = destinationFolder + "\\" + filename; if (!destinationFolder.exists()) { destinationFolder.mkdir(); } if (file.renameTo(new File(destinationFilePath))) { //System.out.println(String.format("File '%s' is moved successful to folder:\n%s\n", filename, destinationFolder)); return true; } else { //System.out.println(String.format("File '%s' is failed to move to folder: \n%s\n", filename, destinationFolder)); return false; } }
From source file:com.netflix.priam.backup.MetaData.java
public static File createTmpMetaFile() throws IOException { File metafile = File.createTempFile("meta", ".json"); File destFile = new File(metafile.getParent(), "meta.json"); if (destFile.exists()) destFile.delete();/* w w w .ja v a2 s .c o m*/ FileUtils.moveFile(metafile, destFile); return destFile; }
From source file:net.refractions.udig.document.source.ShpDocUtils.java
/** * Gets the absolute path with the url as the parent path and the relative path as the child * path./*from www . ja v a 2 s . c o m*/ * * @param url * @param relativePath * @return absolute path */ public static String getAbsolutePath(URL url, String relativePath) { if (relativePath != null && relativePath.trim().length() > 0) { try { final File parentFile = new File(new URI(url.toString())); final File childFile = new File(parentFile.getParent(), relativePath); return childFile.getAbsolutePath(); } catch (URISyntaxException e) { // Should not happen as shapefile should be a valid file e.printStackTrace(); } } return null; }
From source file:com.opensymphony.util.FileUtils.java
public final static File checkBackupDirectory(File file) { File backupDirectory = new File(file.getParent() + System.getProperty("file.separator") + "osedit_backup"); if (!backupDirectory.exists()) { backupDirectory.mkdirs();/*from w w w .jav a 2s . c o m*/ } return backupDirectory; }
From source file:fiftyone.mobile.detection.webapp.ImageCache.java
/** * Adds the image at the width and height provided to the cache. * @param imageLocal//from w ww. j ava2 s . c o m * @param width * @param height * @param imageAsStream * @throws IOException */ synchronized static void add(File physicalPath, File cacheFile, int width, int height, InputStream imageAsStream) throws IOException { new File(cacheFile.getParent()).mkdirs(); cacheFile.createNewFile(); OutputStream outputStream = new FileOutputStream(cacheFile); int read = 0; byte[] bytes = new byte[1024 ^ 2]; while ((read = imageAsStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } outputStream.close(); }
From source file:com.github.megatronking.svg.cli.Main.java
private static void svg2vectorForFile(File inputFile, File outputFile, int width, int height) { if (inputFile.getName().endsWith(".svgz")) { File tempUnzipFile = new File(inputFile.getParent(), FileUtils.noExtensionLastName(inputFile) + ".svg"); try {/* www . ja v a2 s . c om*/ FileUtils.unZipGzipFile(inputFile, tempUnzipFile); svg2vectorForFile(tempUnzipFile, outputFile, width, height); } catch (IOException e) { throw new RuntimeException("Unzip file occur an error: " + e.getMessage()); } finally { tempUnzipFile.delete(); } } else if (inputFile.getName().endsWith(".svg")) { Svg2Vector.parseSvgToXml(inputFile, outputFile, width, height); } }
From source file:com.chinamobile.bcbsp.fault.tools.Zip.java
/** * Uncompress *.zip files./*from www.j a v a 2 s . com*/ * @param fileName * : file to be uncompress */ @SuppressWarnings("unchecked") public static void decompress(String fileName) { File sourceFile = new File(fileName); String filePath = sourceFile.getParent() + "/"; try { BufferedInputStream bis = null; BufferedOutputStream bos = null; ZipFile zipFile = new ZipFile(fileName); Enumeration en = zipFile.entries(); byte[] data = new byte[BUFFER]; while (en.hasMoreElements()) { ZipEntry entry = (ZipEntry) en.nextElement(); if (entry.isDirectory()) { new File(filePath + entry.getName()).mkdirs(); continue; } bis = new BufferedInputStream(zipFile.getInputStream(entry)); File file = new File(filePath + entry.getName()); File parent = file.getParentFile(); if (parent != null && (!parent.exists())) { parent.mkdirs(); } bos = new BufferedOutputStream(new FileOutputStream(file)); int count; while ((count = bis.read(data, 0, BUFFER)) != -1) { bos.write(data, 0, count); } bis.close(); bos.close(); } zipFile.close(); } catch (IOException e) { //LOG.error("[compress]", e); throw new RuntimeException("[compress]", e); } }
From source file:it.inserpio.mapillary.gopro.importer.GoProTimeLapseShotsMapillaryImporter.java
/** * @param bikeMateProGPXFileName//from ww w .ja v a2s . com * @param goProImagesDirectoryName * @throws ParseException * @throws IOException * @throws GPXParsingException * @throws XmlMappingException * @throws CoordinatesNotFoundException * @throws ImageReadException * @throws ImageWriteException */ public static void uploadToMapillary(String bikeMateProGPXFileName, String goProImagesDirectoryName) throws XmlMappingException, GPXParsingException, IOException, ParseException, ImageReadException, CoordinatesNotFoundException, ImageWriteException { // Get Date-Time Points from GPX file // ------------------------------------------------------------------------------------------ GPXParser gpxParser = new BikeMateProGPXParser(); List<GPXDateTimePoint> gpxDateTimePoints = gpxParser.parse(new File(bikeMateProGPXFileName)); File goProImagesDirectory = new File(goProImagesDirectoryName); Assert.isTrue(goProImagesDirectory.isDirectory()); File destinationDirectory = new File( goProImagesDirectory.getParent() + File.separator + "uploadable-images"); if (!destinationDirectory.exists()) { destinationDirectory.mkdir(); } File[] imageFiles = goProImagesDirectory.listFiles(); // It sets gps coordinates for every GoPro time-lapse shot and upload to Mapillary // ------------------------------------------------------------------------------------------ for (int imageIndex = 0; imageIndex < imageFiles.length; imageIndex++) { File imageFile = imageFiles[imageIndex]; System.out.println("Managing image " + imageFile); Coordinates coordinates = Image2GeoMatcher.findCoordinatesByImageOriginalDateTime(imageFile, gpxDateTimePoints, 0); File modifiedImageFile = new File(destinationDirectory, imageFile.getName()); EXIFPropertyWriter.setExifGPSTag(imageFile, modifiedImageFile, coordinates); UploadToMapillary.upload(modifiedImageFile, "", "", ""); // TODO upload not yet implemented } }