List of usage examples for java.io File getAbsolutePath
public String getAbsolutePath()
From source file:Main.java
public static String getTablesFolder(String appName, String tableId) { String path;/*from www . java 2s .c om*/ if (tableId == null || tableId.length() == 0) { throw new IllegalArgumentException("getTablesFolder: tableId is null or the empty string!"); } else { if (!tableId.matches("^\\p{L}\\p{M}*(\\p{L}\\p{M}*|\\p{Nd}|_)+$")) { throw new IllegalArgumentException( "getFormFolder: tableId does not begin with a letter and contain only letters, digits or underscores!"); } path = getTablesFolder(appName) + File.separator + tableId; } File f = new File(path); f.mkdirs(); return f.getAbsolutePath(); }
From source file:Main.java
static public String checkFile(String fileName, String dir) { File dictionaryRoot = new File(Environment.getExternalStorageDirectory(), dir); File dictionaryFile = new File(dictionaryRoot, fileName.substring(0, 1)); File filePath = new File(dictionaryFile, fileName + ".mp3"); if (filePath.exists()) { return filePath.getAbsolutePath(); }/*from w w w . jav a 2 s .c om*/ return null; }
From source file:Main.java
/** * create a new photo file on store card * @param subFolder/*from ww w . j a v a2s . c om*/ * @param ext * @return */ public static File getNewFile(File subFolder, String ext) { int idx = 1; File file; do { file = new File(subFolder.getAbsolutePath() + String.format("/pics_%d" + ext, idx++)); } while (file.exists()); return file; }
From source file:Main.java
public static URL createURL(String fileName) throws MalformedURLException { URL url = null;// w w w . jav a 2s. c o m try { url = new URL(fileName); } catch (MalformedURLException ex) { File f = new File(fileName); try { String path = f.getAbsolutePath(); String fs = System.getProperty("file.separator"); if (fs.length() == 1) { char sep = fs.charAt(0); if (sep != '/') { path = path.replace(sep, '/'); } if (path.charAt(0) != '/') { path = '/' + path; } } path = "file://" + path; url = new URL(path); } catch (MalformedURLException e) { throw e; } } return url; }
From source file:Main.java
private static String getFileRoot(Context context) { if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { File external = context.getExternalFilesDir(null); if (external != null) { return external.getAbsolutePath(); }//w w w .jav a 2 s .c o m } return context.getFilesDir().getAbsolutePath(); }
From source file:hu.bme.mit.incqueryd.engine.util.EObjectSerializer.java
public static String serializeToString(final EObject eObject) throws IOException { Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("json", new JsonResourceFactory()); final File tempFile = createTempFile(); serializeToFile(eObject, tempFile.getAbsolutePath()); final String modelString = FileUtils.readFileToString(tempFile); return modelString; }
From source file:Main.java
public static void listFilesInDirectory(File dir) throws Exception { String tempfolder = System.getProperty("java.io.tmpdir"); String pathRequiredForFile = null; File[] files = dir.listFiles(); if (files == null) { return;/*from w ww .j ava 2 s . c om*/ } for (File f : files) { if (f.isDirectory()) { pathRequiredForFile = f.getName(); listFilesInDirectory(f); } else { System.out.println(f.getName()); File path = new File(tempfolder + "//" + pathRequiredForFile); path.mkdir(); OutputXml(f, path.getAbsolutePath()); } } }
From source file:com.ewcms.common.io.HtmlFileUtil.java
public static File normalizeFile(File f) { String path = f.getAbsolutePath(); path = normalizePath(path);//from w w w .j a v a 2s . c o m return new File(path); }
From source file:Main.java
public static String getCachePath(Context context) { File f = context.getCacheDir(); if (null == f) { return null; } else {//from w ww .j a v a 2 s . c om return f.getAbsolutePath() + "/"; } }
From source file:Main.java
/** * Write the given bitmap to a file in the external storage. Requires * "android.permission.WRITE_EXTERNAL_STORAGE" permission. *//*from w w w . j av a 2 s. c o m*/ public static void writeToFile(Bitmap bitmap, String dir, String filename) throws FileNotFoundException, IOException { File sdCard = Environment.getExternalStorageDirectory(); File dirFile = new File(sdCard.getAbsolutePath() + "/" + dir); dirFile.mkdirs(); File f = new File(dirFile, filename); FileOutputStream fos = new FileOutputStream(f, false); bitmap.compress(CompressFormat.PNG, 100 /*ignored for PNG*/, fos); fos.flush(); fos.close(); }