List of usage examples for java.io File getPath
public String getPath()
From source file:Main.java
static private List<File> getFiles(String src) { List<File> list = new ArrayList<File>(); File f = new File(src); File files[] = f.listFiles(); for (File file : files) { if (file.isFile()) { list.add(file);/*from w ww.j a v a 2s .c o m*/ } else { list.addAll(getFiles(file.getPath())); } } return list; }
From source file:Main.java
@SuppressWarnings("unused") public static long getTotalBytes(File dir) { if (!dir.exists() && !dir.mkdirs()) { return 0; }/*from w w w . j ava2 s . com*/ StatFs dirStatFs = new StatFs(dir.getPath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return dirStatFs.getTotalBytes(); } else { //noinspection deprecation return (long) dirStatFs.getBlockCount() * dirStatFs.getBlockSize(); } }
From source file:Main.java
@SuppressWarnings("WeakerAccess") public static long getAvailableBytes(File dir) { if (!dir.exists() && !dir.mkdirs()) { return 0; }/*from ww w .j a v a 2s. co m*/ StatFs dirStatFs = new StatFs(dir.getPath()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { return dirStatFs.getAvailableBytes(); } else { //noinspection deprecation return (long) dirStatFs.getAvailableBlocks() * dirStatFs.getBlockSize(); } }
From source file:com.wendal.java.dex.decomplier.toolkit.IO_Tool.java
public static void write2File(String rootDir, String package_name, String filename, String data) throws IOException { String tmp[] = package_name.split("[.]"); String tmp_str = rootDir;/*ww w . j a va 2 s .co m*/ for (int i = 0; i < tmp.length; i++) { tmp_str += "\\"; tmp_str += tmp[i]; } File dir_file = new File(tmp_str + "\\"); dir_file.mkdirs(); File src_file = new File(dir_file.getPath() + "\\" + filename); src_file.createNewFile(); FileUtils.writeStringToFile(src_file, data); }
From source file:Main.java
private static void zipFile(ZipOutputStream zipOutputStream, String sourcePath) throws IOException { java.io.File files = new java.io.File(sourcePath); java.io.File[] fileList = files.listFiles(); String entryPath = ""; BufferedInputStream input = null; for (java.io.File file : fileList) { if (file.isDirectory()) { zipFile(zipOutputStream, file.getPath()); } else {/*from w w w .j a va 2s .c om*/ byte data[] = new byte[BUFFER_SIZE]; FileInputStream fileInputStream = new FileInputStream(file.getPath()); input = new BufferedInputStream(fileInputStream, BUFFER_SIZE); entryPath = file.getAbsolutePath().replace(parentPath, ""); ZipEntry entry = new ZipEntry(entryPath); zipOutputStream.putNextEntry(entry); int count; while ((count = input.read(data, 0, BUFFER_SIZE)) != -1) { zipOutputStream.write(data, 0, count); } input.close(); } } }
From source file:Main.java
public static long availableSDCard() { File path = Environment.getExternalStorageDirectory(); long availableSize = 0; if (path != null) { StatFs stat = new StatFs(path.getPath()); long blockSize = stat.getBlockSize(); long availableBlock = stat.getAvailableBlocks(); availableSize = availableBlock * blockSize; }/* w ww . jav a2 s . com*/ return availableSize / (1024 * 1024); }
From source file:Main.java
public static String getNewTemporaryFilePath(Context context, Uri uri) { File file = getFile(context, uri, true); return file == null ? null : file.getPath(); }
From source file:com.gargoylesoftware.js.CodeUpdater.java
private static void processFile(final File originalFile, final boolean isMain) throws IOException { String relativePath = originalFile.getPath().replace('\\', '/'); relativePath = "com/gargoylesoftware/js/" + relativePath.substring(relativePath.indexOf("/jdk/") + "/jdk/".length()); final String root = isMain ? "src/main/java/" : "src/test/java/"; final File localFile = new File(root + relativePath); if (!localFile.exists()) { System.out.println("File doesn't locally exist: " + relativePath); return;/*w ww . j a v a 2 s . c om*/ } final List<String> originalLines = FileUtils.readLines(originalFile); final List<String> localLines = FileUtils.readLines(localFile); while (!isCodeStart(originalLines.get(0))) { originalLines.remove(0); } for (int i = 0; i < localLines.size(); i++) { if (isCodeStart(localLines.get(i))) { while (i < localLines.size()) { localLines.remove(i); } break; } } for (int i = 0; i < originalLines.size(); i++) { String line = originalLines.get(i); line = line.replace("jdk.internal.org.objectweb.asm", "org.objectweb.asm"); line = line.replace("jdk.nashorn.internal", "com.gargoylesoftware.js.nashorn.internal"); line = line.replace("jdk/nashorn/internal", "com/gargoylesoftware/js/nashorn/internal"); line = line.replace("jdk/nashorn/javaadapters", "com/gargoylesoftware/js/nashorn/javaadapters"); line = line.replace("jdk.nashorn.api", "com.gargoylesoftware.js.nashorn.api"); line = line.replace("jdk.nashorn.tools", "com.gargoylesoftware.js.nashorn.tools"); line = line.replace("jdk.internal.dynalink", "com.gargoylesoftware.js.internal.dynalink"); line = line.replace(" @Constructor", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Constructor"); line = line.replace(" @Property", " @com.gargoylesoftware.js.nashorn.internal.objects.annotations.Property"); originalLines.set(i, line); if (line.equals("@jdk.Exported")) { originalLines.remove(i--); } } localLines.addAll(originalLines); FileUtils.writeLines(localFile, localLines); }
From source file:cc.recommenders.utils.Zips.java
public static void zip(File directory, File out) throws IOException { ZipOutputStream zos = null;/*w w w . jav a 2s .c o m*/ try { OutputSupplier<FileOutputStream> s = Files.newOutputStreamSupplier(out); zos = new ZipOutputStream(s.getOutput()); Collection<File> files = FileUtils.listFiles(directory, FILE, DIRECTORY); for (File f : files) { String path = removeStart(f.getPath(), directory.getAbsolutePath() + "/"); ZipEntry e = new ZipEntry(path); zos.putNextEntry(e); byte[] data = Files.toByteArray(f); zos.write(data); zos.closeEntry(); } } finally { Closeables.close(zos, false); } }
From source file:com.hazelcast.qasonar.utils.PropertyReaderBuilder.java
public static PropertyReader fromPropertyFile() throws IOException { File homeDir = new File(System.getProperty("user.home")); File propertyFile = new File(homeDir, ".hazelcast-qa"); return fromPropertyFile(propertyFile.getPath()); }