List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
public static boolean writeFile(String to, String value) { boolean result = false; FileOutputStream out = null;/*w w w . j a va2s.c om*/ try { out = new FileOutputStream(to); byte[] buffer = value.getBytes(); out.write(buffer, 0, value.length()); out.flush(); result = true; } catch (FileNotFoundException e) { } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { } } return result; }
From source file:Main.java
public static Drawable get_scaled_drawable_from_uri_string_for_square_container(Context context, String uri, int max_size) { Drawable drawable = null;// ww w .java2s . c o m Uri img_uri = Uri.parse(uri); if (uri != null) { try { InputStream inputStream = context.getContentResolver().openInputStream(img_uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); int sx = bitmap.getWidth(); int sy = bitmap.getHeight(); int fsx = max_size; int fsy = max_size; if (sy > sx) fsx = (int) ((float) max_size * ((float) sx / (float) sy)); else if (sx > sy) fsy = (int) ((float) max_size * ((float) sy / (float) sx)); Bitmap small_bitmap = Bitmap.createScaledBitmap(bitmap, fsx, fsy, false); bitmap.recycle(); drawable = new BitmapDrawable(context.getResources(), small_bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); } } return drawable; }
From source file:Main.java
public static boolean installDll(Context context) { boolean isSuccess = false; File file = context.getFileStreamPath("Disdll.dll"); boolean isDeleteSuccess = true; if (file.exists()) { isDeleteSuccess = file.delete(); }/*from w w w . j av a 2 s . c o m*/ if (isDeleteSuccess) { try { FileOutputStream outputStream = context.openFileOutput("Disdll.dll", Context.MODE_PRIVATE); InputStream inputStream = context.getAssets().open("Disdll.dll"); byte[] temp = new byte[1024]; int len = -1; while ((len = inputStream.read(temp)) != -1) { outputStream.write(temp, 0, len); } outputStream.flush(); outputStream.close(); inputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } isSuccess = checkIfDllInstalled(context); } return isSuccess; }
From source file:Main.java
public static void saveWeiboBitmap(Bitmap bitmap, String filename) { String status = Environment.getExternalStorageState(); if (bitmap == null || !status.equals(Environment.MEDIA_MOUNTED)) { return;/*from w ww . ja v a 2 s .c o m*/ } File f = new File(filename); FileOutputStream fOut = null; boolean error = false; try { f.createNewFile(); } catch (IOException e1) { e1.printStackTrace(); error = true; } try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); error = true; } try { bitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut); } catch (Exception e) { e.printStackTrace(); error = true; } try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.ricston.akka.matrix.MatrixFile.java
public static MatrixFile readMatrixFile(String filename) { Gson gson = new Gson(); MatrixFile mF = null;// w ww. j a v a 2 s .c o m try { BufferedReader br = new BufferedReader(new FileReader(filename)); mF = gson.fromJson(br, MatrixFile.class); } catch (FileNotFoundException e) { e.printStackTrace(); } return mF; }
From source file:Main.java
public static File copy(File in, String path, String name) { File newFile = null;//from www . j a v a 2s .c om FileInputStream fis = null; try { fis = new FileInputStream(in); newFile = writeFromInput(path, name, fis); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { try { if (fis != null) fis.close(); } catch (IOException e) { e.printStackTrace(); } } return newFile; }
From source file:Main.java
final static private boolean createZipFile(String out, String... in) { InputStream is = null;/*from ww w . java2 s . com*/ ZipOutputStream zos = null; try { zos = new ZipOutputStream(new FileOutputStream(out)); } catch (FileNotFoundException e2) { e2.printStackTrace(); } try { for (int i = 0; i < in.length; i++) { is = new FileInputStream(in[i]); ZipEntry ze = new ZipEntry(in[i]); zos.putNextEntry(ze); int len = 0; byte[] buf = new byte[1024]; while ((len = is.read(buf)) != -1) { zos.write(buf, 0, len); } is.close(); zos.closeEntry(); } zos.close(); } catch (IOException e) { e.printStackTrace(); return false; } return true; }
From source file:Main.java
/** * save the bitmap to local,add give a white bg color * @param bitmap// w w w.ja v a2s. c om * @param path * @return */ public static boolean saveBitmapNoBgToSdCard(Bitmap bitmap, String path) { BufferedOutputStream bos = null; try { File file = new File(path); if (file.exists()) file.delete(); bos = new BufferedOutputStream(new FileOutputStream(file)); int w = bitmap.getWidth(); int h = bitmap.getHeight(); int w_new = w; int h_new = h; Bitmap resultBitmap = Bitmap.createBitmap(w_new, h_new, Bitmap.Config.ARGB_8888); // Paint paint = new Paint(); // paint.setColor(Color.WHITE); Canvas canvas = new Canvas(resultBitmap); canvas.drawColor(Color.WHITE); canvas.drawBitmap(bitmap, new Rect(0, 0, w, h), new Rect(0, 0, w_new, h_new), null); resultBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos); bos.flush(); resultBitmap.recycle(); return true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (bos != null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } } return false; }
From source file:Main.java
public static Bitmap decodeSampledBitmapFromPath(String path, int reqWidth, int reqHeight) { if (path == null) { return null; }// w w w . j av a 2 s. c o m final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; File file = new File(path); InputStream in = null; try { in = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } BitmapFactory.decodeStream(in, null, options); options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); options.inJustDecodeBounds = false; try { in = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); return null; } return BitmapFactory.decodeStream(in, null, options); }
From source file:Main.java
public static boolean writeFile(byte[] buffer, String folder, String fileName) { boolean writeSucc = false; boolean sdCardExist = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED); String folderPath = ""; if (sdCardExist) { folderPath = Environment.getExternalStorageDirectory() + File.separator + folder + File.separator; } else {//from ww w . ja va2 s. com 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 (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } return writeSucc; }