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
private static File getOutputMediaFile(int type) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), ""); if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("failed", "Oops! Failed create " + "Alumni Space Picture" + " directory"); return null; }// w w w . ja v a 2 s . c o m } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date()); File mediaFile; if (type == 10) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else { return null; } return mediaFile; }
From source file:Main.java
/** Create a File for saving an image*/ private static File getOutputMediaFile(String fileName) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "DFCarChecker"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d("DFCarChecker", "failed to create directory"); return null; }//www.j ava 2 s. c o m } File mediaFile; mediaFile = new File(mediaStorageDir.getPath() + File.separator + fileName + ".jpg"); return mediaFile; }
From source file:Main.java
/** Removes useless path components. */ private static String canonicalize(String path) { String pattern = File.separator; if (pattern.equals("\\")) pattern = "\\\\"; String[] splitted = path.split(pattern); ArrayList<String> pathSpec = new ArrayList<String>(splitted.length); for (int i = 0; i < splitted.length; i++) pathSpec.add(splitted[i]);//from ww w. j a v a2s .co m // Warning: these steps must be performed in this exact order! // Step 1: Remove empty paths for (ListIterator<String> it = pathSpec.listIterator(); it.hasNext();) { String c = it.next(); if (c.length() == 0 && it.previousIndex() > 0) it.remove(); } // Step 2: Remove all occurrences of "." for (ListIterator<String> it = pathSpec.listIterator(); it.hasNext();) { String c = it.next(); if (c.equals(".")) it.remove(); } // Step 3: Remove all occurrences of "foo/.." for (ListIterator<String> it = pathSpec.listIterator(); it.hasNext();) { String c = it.next(); if (c.equals("..") && it.previousIndex() > 0) { if (it.previousIndex() == 1 && pathSpec.get(0).length() == 0) { // "/.." is replaced by "/" it.remove(); } else if (!pathSpec.get(it.previousIndex() - 1).equals("..")) { it.remove(); it.previous(); it.remove(); } } } return listToString(pathSpec); }
From source file:com.norconex.collector.http.util.PathUtils.java
public static String urlToPath(final String url) { if (url == null) { return null; }/*w ww. j a va2s .co m*/ String sep = File.separator; if (sep.equals("\\")) { sep = "\\" + sep; } String domain = url.replaceFirst("(.*?)(://)(.*?)(/)(.*)", "$1_$3"); domain = domain.replaceAll("[\\W]+", "_"); String path = url.replaceFirst("(.*?)(://)(.*?)(/)(.*)", "$5"); path = path.replaceAll("[\\W]+", "_"); StringBuilder b = new StringBuilder(); for (int i = 0; i < path.length(); i++) { if (i % PATH_SEGMENT_SIZE == 0) { b.append(sep); } b.append(path.charAt(i)); } path = b.toString(); //TODO is truncating after 256 a risk of creating false duplicates? if (path.length() > MAX_PATH_LENGTH) { path = StringUtils.right(path, MAX_PATH_LENGTH); if (!path.startsWith(File.separator)) { path = File.separator + path; } } return domain + path; }
From source file:Main.java
public static String getSystemFolder(String appName) { String path = getAppFolder(appName) + File.separator + SYSTEM_FOLDER_NAME; return path; }
From source file:net.orpiske.ssps.common.utils.Utils.java
private static String getUserHomeOrOverride() { String userHome = System.getenv("USER_LOCAL_DIRECTORY"); if (userHome == null) { userHome = FileUtils.getUserDirectoryPath(); }/* w w w.j a v a2 s. com*/ return userHome + File.separator + USER_LOCAL_DIRECTORY; }
From source file:costumetrade.common.util.PdfUtils.java
public static File createImagePdfFile(String urlString) { File tempFile = new File(path + File.separator + UUID.randomUUID().toString() + ".pdf"); try (PDDocument doc = createImagePdf(urlString);) { doc.save(tempFile);//from www .ja va2s . c o m } catch (IOException e) { throw new RuntimeException("?pdf", e); } return tempFile; }
From source file:Main.java
/** * Get file name from the path (without extension) * /*from www . j ava 2 s . c o m*/ * @param filePath * The path of the file * @return String File name without extension * @see <pre> * getFileNameWithoutExtension(null) = null * getFileNameWithoutExtension("") = "" * getFileNameWithoutExtension(" ") = " " * getFileNameWithoutExtension("abc") = "abc" * getFileNameWithoutExtension("a.mp3") = "a" * getFileNameWithoutExtension("a.b.rmvb") = "a.b" * getFileNameWithoutExtension("/home/admin") = "admin" * getFileNameWithoutExtension("/home/admin/a.txt/b.mp3") = "b" * </pre> */ public static String getFileNameWithoutExtension(String filePath) { if (TextUtils.isEmpty(filePath)) { return filePath; } int extenPosi = filePath.lastIndexOf(FILE_EXTENSION_SEPARATOR); int filePosi = filePath.lastIndexOf(File.separator); if (filePosi == -1) { return (extenPosi == -1 ? filePath : filePath.substring(0, extenPosi)); } else { if (extenPosi == -1) { return filePath.substring(filePosi + 1); } else { return (filePosi < extenPosi ? filePath.substring(filePosi + 1, extenPosi) : filePath.substring(filePosi + 1)); } } }
From source file:ezbake.common.openshift.OpenShiftUtil.java
public static String getConfigurationDir() { String repoDir = getRepoDir(); final String ezbakeConfigDir = "config"; String retVal;//w w w . j ava 2 s. co m if (repoDir.endsWith(File.separator)) { retVal = repoDir.concat(ezbakeConfigDir); } else { retVal = Joiner.on(File.separator).join(repoDir, ezbakeConfigDir); } return retVal; }
From source file:com.news.util.UploadFileUtil.java
public static String upload(HttpServletRequest request, String paramName, String fileName) { String result = ""; File file;//from ww w . ja v a 2s . c o m int maxFileSize = 5000 * 1024; int maxMemSize = 5000 * 1024; String filePath = ""; ///opt/apache-tomcat-7.0.59/webapps/noithat //filePath = getServletContext().getRealPath("") + File.separator + "test-upload" + File.separator; filePath = File.separator + File.separator + "opt" + File.separator + File.separator; filePath += "apache-tomcat-7.0.59" + File.separator + File.separator + "webapps"; filePath += File.separator + File.separator + "noithat"; filePath += File.separator + File.separator + "upload" + File.separator + File.separator; filePath += "images" + File.separator; //filePath = "E:" + File.separator; // Verify the content type String contentType = request.getContentType(); System.out.println("contentType=" + contentType); if (contentType != null && (contentType.indexOf("multipart/form-data") >= 0)) { DiskFileItemFactory factory = new DiskFileItemFactory(); // maximum size that will be stored in memory factory.setSizeThreshold(maxMemSize); // Location to save data that is larger than maxMemSize. factory.setRepository(new File("c:\\temp")); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // maximum file size to be uploaded. upload.setSizeMax(maxFileSize); try { // Parse the request to get file items. List fileItems = upload.parseRequest(request); System.out.println("fileItems.size()=" + fileItems.size()); // Process the uploaded file items Iterator i = fileItems.iterator(); while (i.hasNext()) { FileItem fi = (FileItem) i.next(); if (!fi.isFormField() && fi.getFieldName().equals(paramName)) { // Get the uploaded file parameters String fieldName = fi.getFieldName(); int dotPos = fi.getName().lastIndexOf("."); if (dotPos < 0) { fileName += ".jpg"; } else { fileName += fi.getName().substring(dotPos); } boolean isInMemory = fi.isInMemory(); long sizeInBytes = fi.getSize(); // Write the file if (fileName.lastIndexOf("\\") >= 0) { file = new File(filePath + fileName.substring(fileName.lastIndexOf("\\"))); } else { file = new File(filePath + fileName.substring(fileName.lastIndexOf("\\") + 1)); } fi.write(file); System.out.println("Uploaded Filename: " + filePath + fileName + "<br>"); result = fileName; } } } catch (Exception ex) { ex.printStackTrace(); } } return result; }