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 unzip(InputStream is, String dir) throws IOException { File dest = new File(dir); if (!dest.exists()) { dest.mkdirs();// w w w .j a v a 2 s . co 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:Functions.FileUpload.java
public static boolean processFile(String path, FileItemStream item, String houseId, String owner) { if ("".equals(item.getName())) { return false; }/* w w w. j av a2 s . c o m*/ String nm = houseId + item.getName(); System.out.println("nm =====================" + nm); try { File f = new File(path + File.separator + "images/"); if (!f.exists()) {//den uparxei kan o fakelos opote den einai sthn database tpt! System.out.println("Mphke sthn if den exists"); f.mkdir(); File savedFile = new File(f.getAbsoluteFile() + File.separator + nm); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } else { System.out.println("Mphke sthn if exists"); if (database_common_functions.isHouseImageInDatabase(houseId, nm) == 1) { //overwrites current image with name nm. System.out.println("Mphke na kanei overwrite t arxeio"); FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); return true; } else { FileOutputStream fos = new FileOutputStream(f.getAbsoluteFile() + File.separator + nm); InputStream is = item.openStream(); int x = -1; byte b[] = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); //fos.write(x); } fos.flush(); fos.close(); database_common_functions.insertIntoBaseImage(houseId, nm); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; }
From source file:Main.java
public static void unZip(String zipFile, String outputFolder) { byte[] buffer = new byte[BUFFER_SIZE]; try {/*w w w . j av a 2 s .com*/ File folder = new File(outputFolder); if (!folder.exists()) { folder.mkdir(); } ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile)); ZipEntry ze = zis.getNextEntry(); while (ze != null) { String fileName = ze.getName(); File newFile = new File(outputFolder + File.separator + fileName); System.out.println("file unzip : " + newFile.getAbsoluteFile()); if (ze.isDirectory()) { newFile.mkdirs(); } else { FileOutputStream fos = new FileOutputStream(newFile); int len; while ((len = zis.read(buffer)) > 0) { fos.write(buffer, 0, len); } fos.close(); } ze = zis.getNextEntry(); } zis.closeEntry(); zis.close(); System.out.println("Done"); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:dao.CheckIfFileExistsDaoTest.java
@BeforeClass public static void setUpClass() { String fSeparator = File.separator; File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "PAOK"); file.mkdirs();/*from w w w . j a v a2s .co m*/ file = new File( System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "TexnologiaLogismikou2"); file.mkdirs(); }
From source file:Main.java
public static String getExtraPath(String folder) { String storagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + folder; File file = new File(storagePath); if (!file.exists()) { file.mkdir();/* w ww.j a va2s .co m*/ } return storagePath; }
From source file:com.mirth.connect.util.AttachmentUtil.java
public static void writeToFile(String filePath, Attachment attachment, boolean binary) throws IOException { File file = new File(filePath); if (!file.canWrite()) { String dirName = file.getPath(); int i = dirName.lastIndexOf(File.separator); if (i > -1) { dirName = dirName.substring(0, i); File dir = new File(dirName); dir.mkdirs();// w w w . j a va 2 s .c o m } file.createNewFile(); } if (attachment != null && StringUtils.isNotEmpty(filePath)) { FileUtils.writeByteArrayToFile(file, binary ? Base64Util.decodeBase64(attachment.getContent()) : attachment.getContent()); } }
From source file:Main.java
public static File getOutputMediaFile(Context context, String mediaName) { File mediaStorageDir = null;/*from www .ja v a2s. com*/ try { // mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), ImgFolderName); mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), ImgFolderName); } catch (Exception e) { e.printStackTrace(); } if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mediaName); return mediaFile; }
From source file:Main.java
public static File getDiskCacheDir(Context context, String uniqueName) { String cachePath;//from w w w . j a v a 2 s .c o m if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) || !Environment.isExternalStorageRemovable()) { File externalCacheDir = context.getExternalCacheDir(); // context.getExternalCacheDir() maybe null if (externalCacheDir == null) { cachePath = context.getCacheDir().getPath(); } else { cachePath = externalCacheDir.getPath(); } } else { cachePath = context.getCacheDir().getPath(); } File file = new File(cachePath + File.separator + uniqueName); if (!file.exists() && !file.isDirectory()) { file.mkdir(); } return file; }
From source file:Main.java
public static File getSaveFile(String folder, String fileNmae) { File file = new File(Environment.getExternalStorageDirectory().getAbsoluteFile() + File.separator + folder + File.separator + fileNmae); return file.exists() ? file : null; }
From source file:Main.java
/** * kudos: http://www.jondev.net/articles/Unzipping_Files_with_Android_(Programmatically) * @param zipFile// www .j a v a 2 s.c om * @param destinationDirectory */ public static void unZip(String zipFile, String destinationDirectory) { try { FileInputStream fin = new FileInputStream(zipFile); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { Log.v("Decompress", "Unzipping " + ze.getName()); String destinationPath = destinationDirectory + File.separator + ze.getName(); if (ze.isDirectory()) { dirChecker(destinationPath); } else { FileOutputStream fout; try { File outputFile = new File(destinationPath); if (!outputFile.getParentFile().exists()) { dirChecker(outputFile.getParentFile().getPath()); } fout = new FileOutputStream(destinationPath); for (int c = zin.read(); c != -1; c = zin.read()) { fout.write(c); } zin.closeEntry(); fout.close(); } catch (Exception e) { // ok for now. Log.v("Decompress", "Error: " + e.getMessage()); } } } zin.close(); } catch (Exception e) { Log.e("Decompress", "unzip", e); } }