File imgFile = new File("/sdcard/Images/test_image.jpg"); if(imgFile.exists()){ Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); ImageView myImage = (ImageView) findViewById(R.id.imageviewTest); myImage.setImageBitmap(myBitmap); }
private InputFile(File file) throws IOException { if (!file.exists()) { throw new IOException("File not found: " + file.getAbsolutePath()); } this.file = file; }
System.out.println(new File(".").getAbsolutePath());
/** * @param filePath the file path to be validated * @return Returns null if valid otherwise error message */ public static String validateFileInput(String filePath) { File file = new File(filePath); if (!file.exists()) { return "File '" + file.getAbsolutePath() + "' does not exist."; } if (!file.canRead()) { return "Read permission is denied on the file '" + file.getAbsolutePath() + "'"; } if (file.isDirectory()) { return "'" + file.getAbsolutePath() + "' is a direcory. it must be a file."; } return null; }
// Assume block needs to be inside a Try/Catch block. String path = Environment.getExternalStorageDirectory().toString(); OutputStream fOut = null; Integer counter = 0; File file = new File(path, "FitnessGirl"+counter+".jpg"); // the File to save , append increasing numeric counter to prevent files from getting overwritten. fOut = new FileOutputStream(file); Bitmap pictureBitmap = getImageBitmap(myurl); // obtaining the Bitmap pictureBitmap.compress(Bitmap.CompressFormat.JPEG, 85, fOut); // saving the Bitmap to a file compressed as a JPEG with 85% compression rate fOut.flush(); // Not really required fOut.close(); // do not forget to close the stream MediaStore.Images.Media.insertImage(getContentResolver(),file.getAbsolutePath(),file.getName(),file.getName());
private static void setRunningLocation(CliMain m) { mRunningLocation = m.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); try { mRunningLocation = URLDecoder.decode(mRunningLocation, "utf-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } if (mRunningLocation.endsWith(".jar")) { mRunningLocation = mRunningLocation.substring(0, mRunningLocation.lastIndexOf(File.separator) + 1); } File f = new File(mRunningLocation); mRunningLocation = f.getAbsolutePath(); }
File sdCard = Environment.getExternalStorageDirectory(); File dir = new File (sdCard.getAbsolutePath() + "/dir1/dir2"); dir.mkdirs(); File file = new File(dir, "filename"); FileOutputStream f = new FileOutputStream(file); ...
@Override File ensureDirectoryExists( FileSystemAbstraction fileSystem, File dir ) { if ( !dir.exists() && !dir.mkdirs() ) { String message = String.format( "Unable to create directory path[%s] for Neo4j store" + ".", dir.getAbsolutePath() ); throw new RuntimeException( message ); } return dir; } },
private static void checkFile(File file) { if (!file.exists()) { throw new JadxArgsValidateException("File not found " + file.getAbsolutePath()); } if (file.isDirectory()) { throw new JadxArgsValidateException("Expected file but found directory instead: " + file.getAbsolutePath()); } }
/** * Compresses a file into gzip archive. */ public static File gzip(File file) throws IOException { if (file.isDirectory()) { throw new IOException("Can't gzip folder"); } FileInputStream fis = new FileInputStream(file); String gzipName = file.getAbsolutePath() + GZIP_EXT; GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(gzipName)); try { StreamUtil.copy(fis, gzos); } finally { StreamUtil.close(gzos); StreamUtil.close(fis); } return new File(gzipName); }
protected static void deleteRecursively(File f) throws IOException { if (f.isDirectory()) { FileUtils.deleteDirectory(f); } else if (!f.delete()) { System.err.println("Failed to delete file " + f.getAbsolutePath()); } }
private void unzipApkFile(File file, File destFile) throws TinkerPatchException, IOException { String apkName = file.getName(); if (!apkName.endsWith(TypedValue.FILE_APK)) { throw new TinkerPatchException( String.format("input apk file path must end with .apk, yours %s\n", apkName) ); } String destPath = destFile.getAbsolutePath(); Logger.d("UnZipping apk to %s", destPath); FileOperation.unZipAPk(file.getAbsoluteFile().getAbsolutePath(), destPath); }
/** * @param output unsigned apk file output * @throws IOException */ private void generateUnsignedApk(File output) throws IOException { Logger.d("Generate unsigned apk: %s", output.getName()); final File tempOutDir = config.mTempResultDir; if (!tempOutDir.exists()) { throw new IOException(String.format( "Missing patch unzip files, path=%s\n", tempOutDir.getAbsolutePath())); } FileOperation.zipInputDir(tempOutDir, output, null); if (!output.exists()) { throw new IOException(String.format( "can not found the unsigned apk file path=%s", output.getAbsolutePath())); } }
public static FileInfo from(File file) { FileInfo info = new FileInfo(); info.setName(file.getName()); info.setLength(file.length()); info.setParent(file.getParent()); info.setAbsolutePath(file.getAbsolutePath()); info.setFile(file.isFile()); info.setDir(file.isDirectory()); return info; } }
/** * Scans single path. */ protected void scanPath(File file) { String path = file.getAbsolutePath(); if (StringUtil.endsWithIgnoreCase(path, JAR_FILE_EXT)) { if (!acceptJar(file)) { return; } scanJarFile(file); } else if (file.isDirectory()) { scanClassPath(file); } }
private void copyAndReplace (String outputDir, Project project, Map<String, String> values) { File out = new File(outputDir); if (!out.exists() && !out.mkdirs()) { throw new RuntimeException("Couldn't create output directory '" + out.getAbsolutePath() + "'"); } for (ProjectFile file : project.files) { copyFile(file, out, values); } }
public static String getAaptExecutionCommand(String aaptPath, File aapt) throws BrutException { if (! aaptPath.isEmpty()) { File aaptFile = new File(aaptPath); if (aaptFile.canRead() && aaptFile.exists()) { aaptFile.setExecutable(true); return aaptFile.getPath(); } else { throw new BrutException("binary could not be read: " + aaptFile.getAbsolutePath()); } } else { return aapt.getAbsolutePath(); } }
File f = new File("C:\\Hello\\AnotherFolder\\The File Name.PDF"); System.out.println(f.getAbsolutePath().substring(f.getAbsolutePath().lastIndexOf("\\")+1));
public static boolean isSymbolicLink(File parent, String name) throws IOException { if (parent == null) { File f = new File(name); parent = f.getParentFile(); name = f.getName(); } File toTest = new File(parent.getCanonicalPath(), name); return !toTest.getAbsolutePath().equals(toTest.getCanonicalPath()); }
private File resolveLogFileInSpecifiedPath(String logFile) throws FileNotFoundException { File outputDirectory = FileHelper.resolveOutputDirectory(processingEnv); logFile = logFile.replace("{outputFolder}", outputDirectory.getAbsolutePath()); return new File(logFile); }