List of usage examples for java.io File getPath
public String getPath()
From source file:com.cedarsoft.io.LinkUtils.java
/** * Creates a temporary file//from w w w .j a v a2s . c om * * @param prefix the prefix * @param suffix the suffix * @param parentDir the parent dir * @return the created file */ @Nonnull public static File createTempFile(@Nonnull String prefix, @Nonnull String suffix, @Nullable File parentDir) { Random rand = new Random(); String parent = parentDir == null ? System.getProperty("java.io.tmpdir") : parentDir.getPath(); DecimalFormat fmt = new DecimalFormat("#####"); File result; do { result = new File(parent, prefix + fmt.format(Math.abs(rand.nextInt())) + suffix); } while (result.exists()); return result; }
From source file:com.microfocus.application.automation.tools.uft.utils.UftToolUtils.java
/** * Retrieves the mtbx path, a test path or the list of tests inside a folder * * @param folder the test path setup in the configuration (can be the an mtbx file, a single test or a folder containing other tests) * @return a list of tests// w ww. j a va 2 s .c o m */ public static List<String> listFilesForFolder(final File folder) { List<String> buildTests = new ArrayList<>(); if (!folder.isDirectory() && folder.getName().contains("mtbx")) { buildTests.add(folder.getPath().trim()); return buildTests; } if (folder.isDirectory()) { for (final File fileEntry : folder.listFiles()) { if (fileEntry.isDirectory()) { if (fileEntry.getName().contains("Action")) { buildTests.add(folder.getPath().trim());//single test break; } else { buildTests.add(fileEntry.getPath().trim()); } } } } return buildTests; }
From source file:com.spidasoftware.EclipseFormatter.Formatter.java
/** * A three-argument method that will take a filename string, the contents of * that file as a string (before formatted), and the Command-Line arguments and * format the respective file.//from w w w .j a v a 2s. co m * * @param file File that will be formatted * @param cmd the list of command-line arguments. */ public static String formatOne(File file, CommandLine cmd) { String nameWithDate = null; String extension = FilenameUtils.getExtension(file.getPath()); if (extension.length() > 0) { nameWithDate = formatUsingExtension(file, cmd); } else { nameWithDate = formatUsingHashBang(file, cmd); } return nameWithDate; }
From source file:com.bigtobster.pgnextractalt.commands.TestCommandContext.java
/** * Builds an import command/*from w w w . j av a2s.c o m*/ * * @param file The file being imported * @return The full, complete import command including the reference to the file to be imported */ static String buildImportCommand(final File file) { //Execute command final HashMap<String, String> optionArgs = new HashMap<String, String>(1); optionArgs.put(IOCommands.FILE_PATH_OPTION, file.getPath()); return TestCommandContext.buildCommand(IOCommands.getImportCommand(), optionArgs); }
From source file:com.bellman.bible.service.common.FileManager.java
public static boolean copyFile(File fromFile, File toFile) { boolean ok = false; try {/*from w ww . j av a 2 s . co m*/ // don't worry if tofile exists, allow overwrite if (fromFile.exists()) { //ensure the target dir exists or FileNotFoundException is thrown creating dst FileChannel File toDir = toFile.getParentFile(); toDir.mkdir(); long fromFileSize = fromFile.length(); log.debug("Source file length:" + fromFileSize); if (fromFileSize > CommonUtils.getFreeSpace(toDir.getPath())) { // not enough room on SDcard ok = false; } else { // move the file FileInputStream srcStream = new FileInputStream(fromFile); FileChannel src = srcStream.getChannel(); FileOutputStream dstStream = new FileOutputStream(toFile); FileChannel dst = dstStream.getChannel(); try { dst.transferFrom(src, 0, src.size()); ok = true; } finally { src.close(); dst.close(); srcStream.close(); dstStream.close(); } } } else { // fromfile does not exist ok = false; } } catch (Exception e) { log.error("Error moving file to sd card", e); } return ok; }
From source file:Main.java
/** * get all the dex path/*from w w w.jav a 2s. co m*/ * * @param context the application context * @return all the dex path */ public static List<String> getSourcePaths(Context context) throws PackageManager.NameNotFoundException, IOException { ApplicationInfo applicationInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), 0); File sourceApk = new File(applicationInfo.sourceDir); File dexDir = new File(applicationInfo.dataDir, SECONDARY_FOLDER_NAME); List<String> sourcePaths = new ArrayList<String>(); sourcePaths.add(applicationInfo.sourceDir); //add the default apk path //the prefix of extracted file, ie: test.classes String extractedFilePrefix = sourceApk.getName() + EXTRACTED_NAME_EXT; //the total dex numbers int totalDexNumber = getMultiDexPreferences(context).getInt(KEY_DEX_NUMBER, 1); for (int secondaryNumber = 2; secondaryNumber <= totalDexNumber; secondaryNumber++) { //for each dex file, ie: test.classes2.zip, test.classes3.zip... String fileName = extractedFilePrefix + secondaryNumber + EXTRACTED_SUFFIX; File extractedFile = new File(dexDir, fileName); if (extractedFile.isFile()) { sourcePaths.add(extractedFile.getAbsolutePath()); //we ignore the verify zip part } else { throw new IOException("Missing extracted secondary dex file '" + extractedFile.getPath() + "'"); } } return sourcePaths; }
From source file:Main.java
public static void copyFile(File from, File toFile, PrintStream reportStream) { if (reportStream != null) { reportStream.println("Coping file " + from.getAbsolutePath() + " to " + toFile.getAbsolutePath()); }/*from w w w . j ava 2s. c o m*/ if (!from.exists()) { throw new IllegalArgumentException("File " + from.getPath() + " does not exist."); } if (from.isDirectory()) { throw new IllegalArgumentException(from.getPath() + " is a directory. Should be a file."); } try { final InputStream in = new FileInputStream(from); if (!toFile.getParentFile().exists()) { toFile.getParentFile().mkdirs(); } if (!toFile.exists()) { toFile.createNewFile(); } final OutputStream out = new FileOutputStream(toFile); final byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); } catch (final IOException e) { throw new RuntimeException( "IO exception occured while copying file " + from.getPath() + " to " + toFile.getPath(), e); } }
From source file:heigit.ors.util.FileUtility.java
public static String combinePaths(String[] paths) { if (paths.length == 0) { return ""; }// www .j a v a 2s . c o m File combined = new File(paths[0]); int i = 1; while (i < paths.length) { combined = new File(combined, paths[i]); ++i; } return combined.getPath(); }
From source file:apim.restful.importexport.utils.ArchiveGeneratorUtil.java
/** * Generate archive file//from ww w . ja v a2s .co m * * @param directoryToZip Location of the archive * @param fileList List of files to be included in the archive * @throws APIExportException If an error occurs while adding files to the archive */ private static void writeArchiveFile(File directoryToZip, List<File> fileList) throws APIExportException { FileOutputStream fileOutputStream = null; ZipOutputStream zipOutputStream = null; try { fileOutputStream = new FileOutputStream(directoryToZip.getPath() + ".zip"); zipOutputStream = new ZipOutputStream(fileOutputStream); for (File file : fileList) { if (!file.isDirectory()) { addToArchive(directoryToZip, file, zipOutputStream); } } } catch (IOException e) { log.error("I/O error while adding files to archive" + e.getMessage()); throw new APIExportException("I/O error while adding files to archive", e); } finally { IOUtils.closeQuietly(zipOutputStream); IOUtils.closeQuietly(fileOutputStream); } }
From source file:msec.org.TarUtil.java
private static void dearchive(File destFile, TarArchiveInputStream tais) throws Exception { TarArchiveEntry entry = null;/* w ww.j a v a 2 s . c o m*/ while ((entry = tais.getNextTarEntry()) != null) { // String dir = destFile.getPath() + File.separator + entry.getName(); File dirFile = new File(dir); // fileProber(dirFile); if (entry.isDirectory()) { dirFile.mkdirs(); } else { dearchiveFile(dirFile, tais); } } }