List of usage examples for java.io File getPath
public String getPath()
From source file:com.exalttech.trex.util.files.FileManager.java
public static String getFileContent(File fileToRead) throws IOException { byte[] encoded = Files.readAllBytes(Paths.get(fileToRead.getPath())); return new String(encoded); }
From source file:Main.java
public static Bitmap getScaleBitmap(File file, int destW, int destH) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true;/*from w w w .j av a 2s .c om*/ BitmapFactory.decodeFile(file.getPath(), opts); opts.inSampleSize = getSampleSize(opts.outWidth, opts.outHeight, destW, destH); opts.inJustDecodeBounds = false; Bitmap bmp = BitmapFactory.decodeFile(file.getPath(), opts); return bmp; }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;/*from w w w . j a v a 2 s .c om*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { File externalCacheDir = context.getExternalCacheDir(); // context.getExternalCacheDir() maybe null if (externalCacheDir == null) { cachePath = context.getCacheDir().getPath(); } else { cachePath = externalCacheDir.getPath(); } } else { cachePath = context.getCacheDir().getPath(); } File file = new File(cachePath + File.separator + uniqueName); if (!file.exists() && !file.isDirectory()) { file.mkdir(); } return file; }
From source file:com.izforge.izpack.util.file.FileUtils.java
/** * Interpret the filename as a file relative to the given file * unless the filename already represents an absolute filename. * * @param file the "reference" file for relative paths. This * instance must be an absolute file and must not contain * "./" or "../" sequences (same for \ instead * of /). If it is null, this call is equivalent to * <code>new java.io.File(filename)</code>. * @param filename a file name.// w w w . j a v a 2 s .c o m * @return an absolute file that doesn't contain "./" or * "../" sequences and uses the correct separator for * the current platform. */ public static File resolveFile(File file, String filename) throws Exception { return new File(FilenameUtils.concat(file == null ? null : file.getPath(), filename)); }
From source file:io.proleap.cobol.TestGenerator.java
public static void generateTestClasses(final File inputDirectory, final File outputDirectory, final String packageName) throws IOException { final String outputDirectoryPath = outputDirectory.getPath(); if (inputDirectory.isDirectory()) { // for each of the files in the directory for (final File inputDirectoryFile : inputDirectory.listFiles()) { // if the file is a Cobol relevant file if (inputDirectoryFile.isFile() && !inputDirectoryFile.isHidden() && isCobolFile(inputDirectoryFile)) { generateTestClass(inputDirectoryFile, outputDirectory, packageName); generateTreeFile(inputDirectoryFile, inputDirectory); }/*w w w . j a va2s .c om*/ // else, if the file is a relevant directory else if (inputDirectoryFile.isDirectory() && !isDirectoryExcluded(inputDirectoryFile)) { final File subInputDirectory = inputDirectoryFile; final String subInputDirectoryName = subInputDirectory.getName(); if (!".".equals(subInputDirectoryName) && !"..".equals(subInputDirectoryName)) { /* * determine the output directory, where test classes * should be placed */ final File subOutputDirectory = new File(outputDirectoryPath + "/" + subInputDirectoryName); subOutputDirectory.mkdirs(); // determine the package name of test classes final String subPackageName = Strings.isBlank(packageName) ? subInputDirectoryName : packageName + "." + subInputDirectoryName; generateTestClasses(subInputDirectory, subOutputDirectory, subPackageName); } } } } }
From source file:Main.java
public static Bitmap decodeSampledBitmapFileForSize(File f, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true;/*w w w .j av a2s . c o m*/ BitmapFactory.decodeFile(f.getPath(), options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeFile(f.getPath(), options); }
From source file:css.variable.converter.CSSVariableConverter.java
private static void loadCSSFiles(File releaseDirectory) { CSSFilter theCSSFilter = new CSSFilter(); DirectoryFilter theDirectoryFilter = new DirectoryFilter(); ArrayList<String> theDirectoryList = new ArrayList<String>(); // We're about to go look for every CSS file in a sub directory theDirectoryList.add(releaseDirectory.getAbsolutePath());// Add the current directory while (!theDirectoryList.isEmpty()) { File currentDirectory = new File(theDirectoryList.get(0)); File[] currentCSSFiles = currentDirectory.listFiles(theCSSFilter); File[] subDirectories = currentDirectory.listFiles(theDirectoryFilter); // Add any css files found to theCSSList if (currentCSSFiles != null) { for (File cssFile : currentCSSFiles) { theCSSList.add(cssFile); }//w w w .j a va2 s.c o m } // Add any more subdirectories found to the directory list. if (subDirectories != null) { for (File dir : subDirectories) { theDirectoryList.add(dir.getPath()); } } // Remove current directory. theDirectoryList.remove(0); } }
From source file:de.dakror.jagui.parser.NGuiParser.java
public static JSONObject replaceGuidDeep(JSONObject data, HashMap<String, File> guids, File sel) { for (String key : JSONObject.getNames(data)) { try {//from w w w . j a v a2s . c o m if (data.get(key) instanceof JSONArray) { for (int i = 0; i < data.getJSONArray(key).length(); i++) { if (data.getJSONArray(key).get(i) instanceof JSONObject) data.getJSONArray(key).put(i, replaceGuidDeep(data.getJSONArray(key).getJSONObject(i), guids, sel)); } } else if (data.get(key) instanceof JSONObject) { if (data.getJSONObject(key).has("r") && data.getJSONObject(key).has("g") && data.getJSONObject(key).has("b") && data.getJSONObject(key).has("a")) { String r = Integer .toHexString((int) Math.round(data.getJSONObject(key).getDouble("r") * 255)); r = r.length() == 1 ? "0" + r : r; String g = Integer .toHexString((int) Math.round(data.getJSONObject(key).getDouble("g") * 255)); g = g.length() == 1 ? "0" + g : g; String b = Integer .toHexString((int) Math.round(data.getJSONObject(key).getDouble("b") * 255)); b = b.length() == 1 ? "0" + b : b; data.getJSONObject(key).remove("r"); data.getJSONObject(key).remove("g"); data.getJSONObject(key).remove("b"); data.getJSONObject(key).put("rgb", "#" + r + g + b); continue; } if (data.getJSONObject(key).has("fileID") && data.getJSONObject(key).getInt("fileID") == 0) { data.put(key, JSONObject.NULL); continue; } if (data.getJSONObject(key).has("guid") && (data.getJSONObject(key).get("guid") instanceof String)) { File f = guids.get(data.getJSONObject(key).getString("guid")); if (f != null) { data.put(key, f.getPath().replace(sel.getParentFile().getPath() + "\\", "") .replace("\\", "/")); continue; } } data.put(key, replaceGuidDeep(data.getJSONObject(key), guids, sel)); } } catch (JSONException e) { e.printStackTrace(); } } return data; }
From source file:com.aspose.email.examples.outlook.pst.SplitAndMergePSTFile.java
public static void deleteAllFilesInDirectory(File dir) { for (String s : dir.list()) { File currentFile = new File(dir.getPath(), s); currentFile.delete();//from w w w . ja va2 s . c om } }
From source file:com.jug6ernaut.android.utilites.FileDownloader.java
public static String stringFromFile(File url) { String stringURL = url.getPath(); if (stringURL.startsWith("http:/") && !stringURL.startsWith("http://")) stringURL = stringURL.replace("http:/", "http://"); if (stringURL.startsWith("https:/") && !stringURL.startsWith("https://")) stringURL = stringURL.replace("https:/", "https://"); return stringURL; }