List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void saveBitmap(Bitmap bm, String picName) { try {//from w ww.j a v a 2s .c om if (!isFileExist("")) { File tempf = createSDDir(""); } File f = new File(SDPATH, picName + ".JPEG"); if (f.exists()) { f.delete(); } FileOutputStream out = new FileOutputStream(f); bm.compress(Bitmap.CompressFormat.JPEG, 90, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Metodo que recebe caminho e nome de um arquivo XML e devolve um String * com seu conteudo/*from ww w . j a va 2s . co m*/ * * @param nomeArquivo * @return String com o conteudo do arquivo */ public static String fileToString(String nomeArquivo) { InputStream input; InputStreamReader reader; BufferedReader buffer; String texto = "", linha; try { input = new FileInputStream(nomeArquivo); reader = new InputStreamReader(input); buffer = new BufferedReader(reader); linha = buffer.readLine(); while (linha != null) { // linha = linha.replace("<", "\n<"); texto += linha; linha = buffer.readLine(); } buffer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return texto; }
From source file:Main.java
public static byte[] readFile(String filePath) { try {//from w w w. j a v a2s. co m if (isFileExist(filePath)) { FileInputStream fi = new FileInputStream(filePath); return readInputStream(fi); } } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static boolean writeParcelable(Context context, String fileName, Parcelable parcelObject) { boolean success = false; FileOutputStream fos = null;/*from w w w. j a va 2s .co m*/ try { fos = context.openFileOutput(fileName, Context.MODE_PRIVATE); Parcel parcel = Parcel.obtain(); parcel.writeParcelable(parcelObject, Parcelable.PARCELABLE_WRITE_RETURN_VALUE); byte[] data = parcel.marshall(); fos.write(data); success = true; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (fos != null) { try { fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } return success; }
From source file:Main.java
public static Bitmap readBitmapFile(String aFileName) { Bitmap bitmap = null;/*from ww w. ja v a2s. co m*/ File file = new File(aFileName); try { FileInputStream fis = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fis); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static Bitmap readBitmapFile(String aFileName, Options aOptions) { Bitmap bitmap = null;// w w w. j a v a 2 s. co m File file = new File(aFileName); try { FileInputStream fis = new FileInputStream(file); bitmap = BitmapFactory.decodeStream(fis, null, aOptions); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OutOfMemoryError e) { e.printStackTrace(); } return bitmap; }
From source file:Main.java
public static String imgCacheRead(Context context, String cacheImgFileName) { int len = 1024; byte[] buffer = new byte[len]; try {//from www . j ava 2s .c o m FileInputStream fis = context.openFileInput(cacheImgFileName); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int nrb = fis.read(buffer, 0, len); // read up to len bytes while (nrb != -1) { baos.write(buffer, 0, nrb); nrb = fis.read(buffer, 0, len); } buffer = baos.toByteArray(); fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { return new String(buffer, "utf-8"); } catch (UnsupportedEncodingException e) { return null; } }
From source file:Main.java
public static String[] GetSupportedFileSystems() { try {/*from w w w .java 2 s . com*/ FileInputStream fProcFS = new FileInputStream(new File("/proc/filesystems")); ArrayList<String> filesystems = new ArrayList<String>(); byte[] data1 = new byte[1024]; int len = fProcFS.read(data1); fProcFS.close(); String fs = new String(data1, 0, len); if (fs.contains("rfs")) filesystems.add("rfs"); if (fs.contains("jfs")) filesystems.add("jfs"); if (fs.contains("ext2")) filesystems.add("ext2"); if (fs.contains("ext3")) filesystems.add("ext3"); if (fs.contains("ext4")) filesystems.add("ext4"); String[] List = (String[]) filesystems.toArray(new String[filesystems.size()]); return List; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static void WriteToFile(String name, Bitmap bitmap, String path) throws IOException { String fString = name.replaceAll("/", "."); File dir = new File("/sdcard/OneBus/user/" + path); if (!dir.exists()) { dir.mkdirs();/*w ww . j av a 2s .c o m*/ } File f = new File("/sdcard/OneBus/user/" + path + "/" + fString + ".jpg"); f.createNewFile(); FileOutputStream fOut = null; try { fOut = new FileOutputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } bitmap.compress(Bitmap.CompressFormat.PNG, 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 void savePic2SD(Bitmap bitmap, String path, String folder) { boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED); if (sdCardExist) { File fileDir = new File(folder); if (!fileDir.exists()) { fileDir.mkdir();/*from w w w . j a v a 2 s . com*/ } } File file = new File(path); if (file.exists()) { file.delete(); } try { FileOutputStream out = new FileOutputStream(file); if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) { out.flush(); out.close(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }