List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void setCookie(Context context, String url) { FileInputStream in = null;/* ww w. j a v a 2 s . c o m*/ try { in = context.openFileInput(TAXICOOKIE_FILE); } catch (FileNotFoundException e) { e.printStackTrace(); } if (in == null) { Log.w(TAG, "saveCookie: Cannot open file: " + TAXICOOKIE_FILE); } BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String cookieStr = null; try { cookieStr = reader.readLine(); reader.close(); } catch (IOException e) { e.printStackTrace(); } Log.d(TAG, "cookieStr: " + cookieStr); if (cookieStr == null) { return; } CookieSyncManager.createInstance(context); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeSessionCookie(); cookieManager.setCookie(url, cookieStr); CookieSyncManager.getInstance().sync(); }
From source file:Main.java
public static int[] getImageSize(String filePath) { int[] size = new int[2]; FileInputStream fis = null;//from www. j ava 2 s.co m try { fis = new FileInputStream(new File(filePath)); } catch (FileNotFoundException e) { e.printStackTrace(); size[0] = size[1] = -1; return size; } try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeStream(fis, null, options); size[0] = options.outWidth; size[1] = options.outHeight; } catch (Exception e) { e.printStackTrace(); size[0] = size[1] = -1; return size; } finally { try { if (fis != null) { fis.close(); fis = null; } } catch (IOException e) { e.printStackTrace(); } } return size; }
From source file:Main.java
public static long getRunningProcess() { File file = new File("/proc/meminfo"); BufferedReader bufferedReader = null; String total = null;//from ww w . j a v a 2 s .com try { bufferedReader = new BufferedReader(new FileReader(file)); String line = bufferedReader.readLine(); char[] charArray = line.toCharArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < charArray.length; i++) { char c = charArray[i]; if (c >= '0' && c <= '9') { sb.append(c); } } total = sb.toString(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } long number = Long.parseLong(total) * 1024; return number; }
From source file:Main.java
public static boolean writeFile(Context context, String fileName, String content) { boolean success = false; FileOutputStream fos = null;//from w w w. j a va2 s .co m try { fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); byte[] byteContent = content.getBytes(); fos.write(byteContent); success = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } return success; }
From source file:Main.java
public static boolean writeFile(String filePath, String content) { boolean success = false; FileOutputStream fos = null;/*from w w w . j a va 2 s . c o m*/ try { fos = new FileOutputStream(filePath); byte[] byteContent = content.getBytes(); fos.write(byteContent); success = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fos != null) fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } return success; }
From source file:Main.java
/** * Return a {@link BufferedInputStream} from the given uri or null if an * exception is thrown/*from w ww .ja v a 2 s . co m*/ * * @param context * @param uri * @return the {@link InputStream} of the given path. null if file is not * found */ static InputStream openContentInputStream(Context context, Uri uri) { try { return context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Return a {@link FileInputStream} from the given path or null if file not * found/*w ww . ja va2 s . co m*/ * * @param path * the file path * @return the {@link FileInputStream} of the given path, null if * {@link FileNotFoundException} is thrown */ static InputStream openFileInputStream(String path) { try { return new FileInputStream(path); } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
private static byte[] getBytesFromFile(File file) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); try {/*from w ww. j av a 2 s .co m*/ FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } int maxBufferSize = 1024 * 1024; int bufferSize = (int) Math.min(file.getTotalSpace(), maxBufferSize); byte[] buffer = new byte[bufferSize]; // read file and write it into form... int bytesRead = 0; if (fileInputStream != null) { bytesRead = fileInputStream.read(buffer, 0, bufferSize); } while (bytesRead > 0) { dataOutputStream.write(buffer, 0, bufferSize); int bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); } } catch (Exception e) { e.printStackTrace(); } return byteArrayOutputStream.toByteArray(); }
From source file:Main.java
public static boolean saveBitmap2file(Bitmap bmp, String filename) { Bitmap.CompressFormat format = Bitmap.CompressFormat.JPEG; int quality = 100; OutputStream stream = null;//www . j a va2 s . c om try { stream = new FileOutputStream(filename); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return bmp.compress(format, quality, stream); }
From source file:Main.java
static boolean saveBitmap2file(Bitmap bmp, String filename) { Bitmap.CompressFormat format = Bitmap.CompressFormat.JPEG; int quality = 100; OutputStream stream = null;//from ww w .j a v a2 s . co m try { stream = new FileOutputStream("/sdcard/" + filename); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } return bmp.compress(format, quality, stream); }