List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
/** * Writes a DOM document to a file.//from w w w .ja v a2 s. c om * * @param document * DOM document. * @param fileName * target file path. */ public static void writeDOMToFile(Document document, String fileName) { FileOutputStream fos; Source source; Result result; Transformer xformer; try { fos = new FileOutputStream(fileName); source = new DOMSource(document); result = new StreamResult(fos); xformer = TransformerFactory.newInstance().newTransformer(); xformer.transform(source, result); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } }
From source file:Main.java
public static final void SaveObject(final String path, final Object saveObject) { FileOutputStream fileOutputStream = null; ObjectOutputStream objectOutputStream = null; File file = new File(path); try {// ww w . ja va2s .com if (!file.exists()) { file.createNewFile(); } fileOutputStream = new FileOutputStream(file); objectOutputStream = new ObjectOutputStream(fileOutputStream); objectOutputStream.writeObject(saveObject); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (objectOutputStream != null) { objectOutputStream.close(); } if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } }
From source file:Main.java
public static String getCpuName() { FileReader fr = null;//from w ww . jav a2s . c om BufferedReader br = null; try { fr = new FileReader("/proc/cpuinfo"); br = new BufferedReader(fr); String text = br.readLine(); String[] array = text.split(":\\s+", 2); for (int i = 0; i < array.length; i++) { } return array[1]; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { e.printStackTrace(); } if (br != null) try { br.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:Main.java
public static Bitmap load_bitmap_from_uri_string(Context context, String uri, int sizeX, int sizeY) { Bitmap small_bitmap = null;// w ww.ja v a 2 s .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); small_bitmap = Bitmap.createScaledBitmap(bitmap, sizeX, sizeY, false); bitmap.recycle(); } catch (FileNotFoundException e) { e.printStackTrace(); } } return small_bitmap; }
From source file:Main.java
public static boolean cache(Context context, String file, byte[] data, int mode) { boolean bResult = false; if (null != data && data.length > 0) { FileOutputStream fos = null; try {//from ww w .j a v a 2s .c om fos = context.openFileOutput(file, mode); fos.write(data); fos.flush(); bResult = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (null != fos) { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } return bResult; }
From source file:Main.java
public static Drawable load_drawable_from_uri_string(Context context, String uri, int sizeX, int sizeY) { Drawable drawable = null;/*from w w w .ja v a2 s. co m*/ Uri img_uri = Uri.parse(uri); if (uri != null) { try { InputStream inputStream = context.getContentResolver().openInputStream(img_uri); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); Bitmap small_bitmap = Bitmap.createScaledBitmap(bitmap, sizeX, sizeY, false); bitmap.recycle(); drawable = new BitmapDrawable(context.getResources(), small_bitmap); } catch (FileNotFoundException e) { e.printStackTrace(); } } return drawable; }
From source file:Main.java
public static String getMD5(String file) { String md5 = ""; try {// w w w . ja v a 2s. co m MessageDigest md = MessageDigest.getInstance("MD5"); InputStream is; is = new FileInputStream(file); DigestInputStream dis = new DigestInputStream(is, md); byte data[] = new byte[1024]; @SuppressWarnings("unused") int count; while ((count = dis.read(data)) != -1) { } byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { md5 += Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1); } return md5; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return md5; }
From source file:Main.java
public static void saveBitmap(String path, Bitmap mBitmap) { File f = new File(path); if (!f.exists()) createDipPath(path);//w ww .jav a2s. c o m FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut); try { fOut.flush(); } catch (IOException e) { e.printStackTrace(); } try { fOut.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static Bitmap getBitmapFromDisk(String url, Context ctx) { Bitmap defautBitmap = null;//from w w w . j a v a 2 s .com try { String filename = constructFileName(url); File filePath = new File(ctx.getCacheDir(), filename); if (filePath.exists() && filePath.isFile() && !filePath.isDirectory()) { FileInputStream fi; BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inPreferredConfig = Config.RGB_565; fi = new FileInputStream(filePath); defautBitmap = BitmapFactory.decodeStream(fi, null, opts); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception e) { } catch (OutOfMemoryError e) { } return defautBitmap; }
From source file:Main.java
/** * Returns a bitmap from a gallery Uri/* w w w .jav a 2 s .c o m*/ * * @param pContext * Context required to access the content resolver * @param pIntent * The Uri of the picker image * @return The picked image as a bitmap */ public static Bitmap getBitmapFromIntent(Context pContext, Intent pIntent) { Bitmap bitmapPickedImage = null; Uri pickedImageUri = pIntent.getData(); // If the URI is not null try to decode it to a bitmap else try to get the bitmap data from the intent // http://stackoverflow.com/questions/17123083/null-pointer-exception-while-taking-pictures-from-camera-android-htc if (pickedImageUri != null) { try { InputStream imageStream = pContext.getContentResolver().openInputStream(pickedImageUri); bitmapPickedImage = BitmapFactory.decodeStream(imageStream); } catch (FileNotFoundException e) { e.printStackTrace(); } } else { if (pIntent.getExtras() != null && pIntent.getExtras().get("data") instanceof Bitmap) { bitmapPickedImage = (Bitmap) pIntent.getExtras().get("data"); } } return bitmapPickedImage; }