List of usage examples for java.io File separator
String separator
To view the source code for java.io File separator.
Click Source Link
From source file:Main.java
public static String getAppFolderPath() { return android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "EasyRSS"; }
From source file:Main.java
public static ArrayList<String> getAssetsImageNamePathList(Context context, String folderName) { ArrayList<String> imagePathList = new ArrayList<String>(); String[] imageNameArray = getAssetsImageNameArray(context, folderName); if (imageNameArray != null && imageNameArray.length > 0 && folderName != null && !folderName.replaceAll(" ", "").trim().equals("")) { for (String imageName : imageNameArray) { imagePathList.add(new StringBuffer(folderName).append(File.separator).append(imageName).toString()); }/*from w ww . ja va 2s . c o m*/ } return imagePathList; }
From source file:Main.java
public static OutputStream openFileStream(String directory, String filePath) { if (TextUtils.isEmpty(directory) || TextUtils.isEmpty(filePath)) { return null; }// ww w . j a v a 2 s .c om File directoryFile = new File(directory); if (!directoryFile.exists()) { directoryFile.mkdirs(); } File file = new File(directory + File.separator + filePath); try { if (!file.exists()) { file.createNewFile(); } return new FileOutputStream(file, true); } catch (Exception ex) { ex.printStackTrace(); return null; } }
From source file:helpers.FileUpload.java
public static boolean processFile(String path, FileItemStream item) { try {/*from w ww .j a v a2 s .c o m*/ File f = new File(path + File.separator + "assets" + File.separator + "uploads"); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception e) { System.out.println("FileUpload 35: " + e.getMessage()); } return false; }
From source file:Main.java
/** * Get the document path (relative to volume name) for a tree URI (LOLLIPOP). * * @param treeUri The tree URI.//from w w w .j a v a 2 s . co m * @return the document path. */ @TargetApi(Build.VERSION_CODES.LOLLIPOP) private static String getDocumentPathFromTreeUri(final Uri treeUri) { final String docId = DocumentsContract.getTreeDocumentId(treeUri); final String[] split = docId.split(":"); if ((split.length >= 2) && (split[1] != null)) { return split[1]; } else { return File.separator; } }
From source file:Main.java
public static String joinPath(String... args) { StringBuilder stringBuilder = new StringBuilder(); for (String arg : args) { stringBuilder.append(File.separator).append(arg.replaceAll("^/+", "")); }/* w w w . j av a 2 s . c om*/ return stringBuilder.toString(); }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { // Check if media is mounted or storage is built-in, if so, try and use // external cache dir // otherwise use internal cache dir final String cachePath = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !isExternalStorageRemovable() ? getExternalCacheDir(context).getPath() : context.getCacheDir().getPath(); return new File(cachePath + File.separator + uniqueName); }
From source file:Main.java
public static String extractFromAssets(Context ctx, String file, String destinationDirectory) throws IOException, FileNotFoundException { final int BUFFER = 2048; BufferedOutputStream dest = null; AssetManager assetManager = ctx.getAssets(); InputStream in = assetManager.open(file); String destinationFilename = destinationDirectory + File.separator + file; OutputStream out = new FileOutputStream(destinationFilename); byte[] buffer = new byte[1024]; int read;// w ww. j a va2s . c o m while ((read = in.read(buffer)) != -1) { out.write(buffer, 0, read); } in.close(); out.close(); return destinationFilename; }
From source file:Main.java
public static boolean isAndroidEmulatorRunning(File androidSdkHome) throws IOException { if (androidSdkHome == null) { return false; }/* w w w . j ava2 s . c o m*/ File adb = new File(androidSdkHome, "platform-tools" + File.separator + "adb"); if (!adb.exists()) { return false; } boolean isEmulatorRunning = false; ProcessBuilder pb = new ProcessBuilder(adb.getAbsolutePath(), "devices"); pb.redirectErrorStream(true); Process p = pb.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = reader.readLine()) != null) { line = line.trim(); if (line.startsWith("List of devices")) { continue; } else if (line.startsWith("emulator-")) { String[] tokens = line.split("\\s"); String name = tokens[0]; String status = tokens[1]; int port = Integer.parseInt(name.substring(name.indexOf("-") + 1)); if (status.equals("device") && port == 5560) { isEmulatorRunning = true; } } } return isEmulatorRunning; }
From source file:Main.java
public static void delAllFiles(File dir) { if (!dir.exists() || !dir.isDirectory()) { return;/*from w w w. j av a 2s . co m*/ } String dirFullName = dir.getAbsolutePath(); String[] fileList = dir.list(); File tempFile = null; for (int i = 0; i < fileList.length; i++) { if (dirFullName.endsWith(File.separator)) { tempFile = new File(dirFullName + fileList[i]); } else { tempFile = new File(dirFullName + File.separator + fileList[i]); } if (tempFile.isFile()) { tempFile.delete(); } if (tempFile.isDirectory()) { delAllFiles(dirFullName + "/" + fileList[i]); delDir(dirFullName + "/" + fileList[i]); } } }