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 void copyDirFile(String oldPath, String newPath) { try {/*from w w w . j ava 2 s .c om*/ new File(newPath).mkdirs(); File a = new File(oldPath); System.out.println("oldPath:" + oldPath); String[] file = a.list(); File temp = null; for (int i = 0; i < file.length; i++) { if (oldPath.endsWith(File.separator)) { temp = new File(oldPath + file[i]); } else { temp = new File(oldPath + File.separator + file[i]); } if (temp.isFile()) { FileInputStream input = new FileInputStream(temp); FileOutputStream output = new FileOutputStream(newPath + "/" + (temp.getName()).toString()); byte[] b = new byte[1024 * 5]; int len; while ((len = input.read(b)) != -1) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } if (temp.isDirectory()) { copyDirFile(oldPath + "/" + file[i], newPath + "/" + file[i]); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void copyFolder(String oldPath, String newPath) { try {//from w w w .jav a 2 s . c o m (new File(newPath)).mkdirs(); File a = new File(oldPath); String[] file = a.list(); File temp = null; for (int i = 0; i < file.length; i++) { if (oldPath.endsWith(File.separator)) { temp = new File(oldPath + file[i]); } else { temp = new File(oldPath + File.separator + file[i]); } if (temp.isFile()) { FileInputStream input = new FileInputStream(temp); FileOutputStream output = new FileOutputStream(newPath + "/" + (temp.getName()).toString()); byte[] b = new byte[1024 * 5]; int len; while ((len = input.read(b)) != -1) { output.write(b, 0, len); } output.flush(); output.close(); input.close(); } if (temp.isDirectory()) { copyFolder(oldPath + "/" + file[i], newPath + "/" + file[i]); } } } catch (Exception e) { Log.e(TAG, "copyFolder() copy dir error", e); } }
From source file:Main.java
public static String compressGzipFile(String filename) { if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) { File flockedFilesFolder = new File( Environment.getExternalStorageDirectory() + File.separator + "FlockLoad"); System.out.println("FlockedFileDir: " + flockedFilesFolder); String uncompressedFile = flockedFilesFolder.toString() + "/" + filename; String compressedFile = flockedFilesFolder.toString() + "/" + "gzip.zip"; try {/*ww w . jav a 2 s .c o m*/ FileInputStream fis = new FileInputStream(uncompressedFile); FileOutputStream fos = new FileOutputStream(compressedFile); GZIPOutputStream gzipOS = new GZIPOutputStream(fos) { { def.setLevel(Deflater.BEST_COMPRESSION); } }; byte[] buffer = new byte[1024]; int len; while ((len = fis.read(buffer)) != -1) { gzipOS.write(buffer, 0, len); } //close resources gzipOS.close(); fos.close(); fis.close(); return compressedFile; } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;/*from w w w. ja va2 s. c o m*/ if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { cachePath = context.getExternalCacheDir().getPath(); } else { cachePath = context.getCacheDir().getPath(); } return new File(cachePath + File.separator + uniqueName); }
From source file:Main.java
public static String getExternalRootDirectory(Context context) { if (databaseFolder == null) { //The location of the temp internal database used for sync should be //in the cache, since it is only needed for <1min at a time, and //created every time it is needed if (useSAF()) { File basePath = new File( context.getCacheDir() + File.separator + "externalDatabaseSync" + File.separator); databaseFolder = basePath.getPath(); } else {/*from ww w. ja va 2 s . c o m*/ return "/storage/usbdisk0/WildRank/cblite"; } } return databaseFolder; }
From source file:Main.java
public static boolean unzipFile(Context context) { try {// w w w. j a v a 2 s . com InputStream is = context.getAssets().open("tessdata.zip"); boolean result = unzipFile(is, dstPath(context) + File.separator + "tessdata"); return result; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:Main.java
private static void fileUnZip(ZipInputStream zis, File file) throws FileNotFoundException, IOException { java.util.zip.ZipEntry zip = null; while ((zip = zis.getNextEntry()) != null) { String name = zip.getName(); File f = new File(file.getAbsolutePath() + File.separator + name); if (zip.isDirectory()) { f.mkdirs();/*from w w w . j a v a 2 s .c o m*/ } else { f.getParentFile().mkdirs(); f.createNewFile(); BufferedOutputStream bos = null; try { bos = new BufferedOutputStream(new FileOutputStream(f)); byte b[] = new byte[2048]; int aa = 0; while ((aa = zis.read(b)) != -1) { bos.write(b, 0, aa); } bos.flush(); } finally { bos.close(); } bos.close(); } } }
From source file:Main.java
public static File getNewFile(Context context, String folderName) { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA); String timeStamp = simpleDateFormat.format(new Date()); String path;// w ww . j a va 2s .c om if (isSDAvailable()) { path = getFolderName(folderName) + File.separator + timeStamp + ".jpg"; } else { path = context.getFilesDir().getPath() + File.separator + timeStamp + ".jpg"; } if (TextUtils.isEmpty(path)) { return null; } return new File(path); }
From source file:Main.java
/***********************************************************************/ public static String locateFile(String fileLocation, String backupPaths[]) throws Exception { String[] newArray = new String[backupPaths.length + 1]; System.arraycopy(backupPaths, 0, newArray, 1, backupPaths.length); newArray[0] = "."; backupPaths = newArray;/* w w w .j ava 2 s .co m*/ for (int i = 0; i < backupPaths.length; i++) { String tfileLocation = backupPaths[i] + File.separator + fileLocation; File file = new File(tfileLocation); if (file.exists()) { return file.getAbsolutePath(); } } throw new Error(String.format("Couldn't find '%s' from locations %s with current directory '%s'", fileLocation, Arrays.asList(backupPaths), new File(".").getAbsolutePath())); }
From source file:Main.java
public static boolean writeFile(byte[] buffer, String folder, String fileName) { boolean writeSucc = false; boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); String folderPath = ""; if (sdCardExist) { folderPath = Environment.getExternalStorageDirectory() + File.separator + folder + File.separator; } else {//from www.j a va 2 s . co m writeSucc = false; } File fileDir = new File(folderPath); if (!fileDir.exists()) { fileDir.mkdirs(); } File file = new File(folderPath + fileName); FileOutputStream out = null; try { out = new FileOutputStream(file); out.write(buffer); writeSucc = true; } catch (Exception e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } return writeSucc; }