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
/** * Salva um objeto xml JAX-B em um arquivo .xml * @param objJAXB/*from w ww. jav a 2 s . c o m*/ * @param dir * @param fileName * @throws Exception */ public static void toFile(Object objJAXB, String dir, String fileName) throws Exception { marshalToFile(objJAXB, dir + File.separator + fileName); }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath); File dir = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!dir.exists()) { dir.mkdirs();/*from ww w.j a v a 2 s . c o m*/ } file.createNewFile(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); } }
From source file:Main.java
/** * @param context// w w w. j a va 2 s. co m * @param filePath file path relative to assets, like request_init1/search_index.json * @return */ public static String readAssert(Context context, String filePath) { try { if (filePath.startsWith(File.separator)) { filePath = filePath.substring(File.separator.length()); } AssetManager assetManager = context.getAssets(); InputStream inputStream = assetManager.open(filePath); DataInputStream stream = new DataInputStream(inputStream); int length = stream.available(); byte[] buffer = new byte[length]; stream.readFully(buffer); ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); byteArrayOutputStream.write(buffer); stream.close(); return byteArrayOutputStream.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.elit2.app.model.FileUpload.java
public static boolean proccessFile(String path, FileItemStream item) { try {// w w w .j av a 2s . com File f = new File(path + File.separator + "images"); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read()) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception ex) { ex.printStackTrace(); } return false; }
From source file:Main.java
public static void deleteSharedPreferences(Context context) { try {/*from w w w . ja va 2s. c om*/ Context appContext = context.getApplicationContext(); ApplicationInfo info = appContext.getPackageManager().getApplicationInfo(appContext.getPackageName(), 0); String dirPath = info.dataDir + File.separator + "shared_prefs" + File.separator; File dir = new File(dirPath); if (dir.exists() && dir.isDirectory()) { String[] list = dir.list(); int size = list.length; for (int i = 0; i < size; i++) { new File(dirPath + list[i]).delete(); } } else { //Log.d("AAA", "NO FILE or NOT DIR"); } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:in.co.sneh.model.CargaExcelRuralModel.java
public static boolean processFile(String path, FileItemStream item) { try {//from w w w .j a va2s. c om File f = new File(path + File.separator + "exceles" + File.separator); if (!f.exists()) { f.mkdir(); } File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName()); FileOutputStream fos = new FileOutputStream(savedFile); InputStream is = item.openStream(); int x = 0; byte[] b = new byte[1024]; while ((x = is.read(b)) != -1) { fos.write(b, 0, x); } fos.flush(); fos.close(); return true; } catch (Exception e) { System.out.println(e.getMessage()); } return false; }
From source file:Main.java
public static URL getURL(String filename) throws MalformedURLException { return new File(System.getProperty("user.dir") + File.separator + filename).toURI().toURL(); }
From source file:Main.java
public static void saveBitmapToFile(Bitmap bitmap, String _file) throws IOException { BufferedOutputStream os = null; try {/*w w w . j a va 2 s .c o m*/ File file = new File(_file); // String _filePath_file.replace(File.separatorChar + // file.getName(), ""); int end = _file.lastIndexOf(File.separator); String _filePath = _file.substring(0, end); File filePath = new File(_filePath); if (!filePath.exists()) { filePath.mkdirs(); } file.createNewFile(); os = new BufferedOutputStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.PNG, 100, os); } finally { if (os != null) { try { os.close(); } catch (IOException e) { Log.e("TAG_ERROR", e.getMessage(), e); } } } }
From source file:Main.java
public static void saveImageToSD(Context ctx, String filePath, Bitmap bitmap, int quality) throws IOException { if (bitmap != null) { File file = new File(filePath.substring(0, filePath.lastIndexOf(File.separator))); if (!file.exists()) { file.mkdirs();/*w w w . j a v a2 s.c o m*/ } BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath)); bitmap.compress(CompressFormat.JPEG, quality, bos); bos.flush(); bos.close(); if (ctx != null) { scanPhoto(ctx, filePath); } } }
From source file:Main.java
public static int saveToSdCard(String fileName, Bitmap bitmap) { int ret = 0;// w w w. j ava2 s.co m PrintStream out = null; if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { return -1; } File file = new File(Environment.getExternalStorageDirectory().toString() + File.separator + fileName); if (!file.getParentFile().exists()) { file.getParentFile().mkdir(); } try { out = new PrintStream(new FileOutputStream(file)); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out); } catch (FileNotFoundException e) { // TODO Auto-generated catch block ret = -2; } finally { out.flush(); out.close(); if (!bitmap.isRecycled()) bitmap.recycle(); } return ret; }