List of usage examples for java.io File separatorChar
char separatorChar
To view the source code for java.io File separatorChar.
Click Source Link
From source file:Main.java
/** * Returns the filename without path and without extension. * //from w ww . ja v a 2 s. c o m * @param fileName * @return the file name without extension and path */ public static String basename(final String fileName) { int dot = fileName.lastIndexOf('.'); int sep = fileName.lastIndexOf(File.separatorChar); if (sep == -1) { sep = fileName.lastIndexOf('\\'); } if (dot == -1) { dot = fileName.length(); } return fileName.substring(sep + 1, dot); }
From source file:Main.java
public static String extractFileName(String _sFilePathName, String _sFileSeparator) { int nPos = -1; if (_sFileSeparator == null) { nPos = _sFilePathName.lastIndexOf(File.separatorChar); if (nPos < 0) { nPos = _sFilePathName.lastIndexOf(File.separatorChar == '/' ? '\\' : '/'); }// w w w . j a v a2 s .com } else { nPos = _sFilePathName.lastIndexOf(_sFileSeparator); } if (nPos < 0) { return _sFilePathName; } return _sFilePathName.substring(nPos + 1); }
From source file:Main.java
/** * Returns the path for a file.<br> * <code>path("/home/user/test.jpg") == "/home/user"</code><br> * Uses the correct pathSeparator depending on the operating system. On * windows c:/test/ is not c:\test\// w ww .jav a 2s . c om * * @param fileName * the name of the file using correct path separators. * @return the path of the file. */ public static String path(final String fileName) { final int sep = fileName.lastIndexOf(File.separatorChar); return fileName.substring(0, sep); }
From source file:Main.java
public static String getFileUnderHome(String str) { char c = File.separatorChar; String appHome = System.getProperty("user.home") + c + ".jetwick"; File f = new File(appHome); if (!f.exists()) f.mkdir();/*from w w w . j a va2 s . co m*/ return appHome + c + str; }
From source file:Main.java
private static File getFile(String parentPath, String pathName) { if (pathName.charAt(0) == File.separatorChar) { return new File(pathName); }/*from ww w .j ava 2s .co m*/ return new File(parentPath, pathName); }
From source file:Main.java
public static boolean isEnvironmentProperlySet() { return new File(System.getProperty("user.home") + File.separatorChar + ".eg", "eg.properties").exists() || new File(System.getenv("EG_HOME") + File.separatorChar + "config", "eg.properties").exists(); }
From source file:Main.java
public static String classNameForPath(String classPath) { String className = classPath.substring(0, classPath.length() - ".class".length()); return className.replace(File.separatorChar, '.'); }
From source file:Main.java
public static void unzip(InputStream is, String dir) throws IOException { File dest = new File(dir); if (!dest.exists()) { dest.mkdirs();//from w w w . j a v a2s. c o m } if (!dest.isDirectory()) throw new IOException("Invalid Unzip destination " + dest); if (null == is) { throw new IOException("InputStream is null"); } ZipInputStream zip = new ZipInputStream(is); ZipEntry ze; while ((ze = zip.getNextEntry()) != null) { final String path = dest.getAbsolutePath() + File.separator + ze.getName(); String zeName = ze.getName(); char cTail = zeName.charAt(zeName.length() - 1); if (cTail == File.separatorChar) { File file = new File(path); if (!file.exists()) { if (!file.mkdirs()) { throw new IOException("Unable to create folder " + file); } } continue; } FileOutputStream fout = new FileOutputStream(path); byte[] bytes = new byte[1024]; int c; while ((c = zip.read(bytes)) != -1) { fout.write(bytes, 0, c); } zip.closeEntry(); fout.close(); } }
From source file:Main.java
public static String clazzName(final File base, final File file) { final int rootLength = base.getAbsolutePath().length(); final String absFileName = file.getAbsolutePath(); final int p = absFileName.lastIndexOf('.'); final String relFileName = absFileName.substring(rootLength + 1, p); return relFileName.replace(File.separatorChar, '.'); }
From source file:Main.java
public static File getSecurityPath(Context context) { return new File(context.getFilesDir().getPath() + File.separatorChar + "bpsec"); }