List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace()
From source file:Main.java
public static Document parseFile(final File aFile, final String propfilename) throws SAXException, ParserConfigurationException { Properties props;//from w w w . j a v a2 s . c o m props = new Properties(); try { InputStream propsStream = new FileInputStream(propfilename); props.load(propsStream); } catch (FileNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex1) { ex1.printStackTrace(); } return parseFile(aFile, props); }
From source file:Main.java
private static byte[] getBytesFromDriveVideoUri(Context context, Uri uri) { InputStream inputStream = null; try {/*from ww w . j av a 2s. c o m*/ inputStream = context.getContentResolver().openInputStream(uri); } catch (FileNotFoundException e) { e.printStackTrace(); } if (inputStream == null) { return null; } int maxBufferSize = 1024 * 1024; int available = 0; try { available = inputStream.available(); } catch (IOException e) { e.printStackTrace(); } if (available == 0) { available = maxBufferSize; } int bufferSize = Math.min(available, maxBufferSize); byte[] data = new byte[bufferSize]; ByteArrayOutputStream buffer = new ByteArrayOutputStream(); int nRead; try { while ((nRead = inputStream.read(data, 0, data.length)) != -1) { buffer.write(data, 0, nRead); } } catch (IOException e) { e.printStackTrace(); } try { buffer.flush(); } catch (IOException e) { e.printStackTrace(); } return buffer.toByteArray(); }
From source file:Main.java
public static void imgCacheWrite(Context context, String cacheImgFileName, String imgBase64Str) { File cacheImgFile = new File(context.getFilesDir() + "/" + cacheImgFileName); if (cacheImgFile.exists()) { cacheImgFile.delete();/*from ww w. java 2s . c o m*/ } FileOutputStream fos; try { fos = context.openFileOutput(cacheImgFileName, Context.MODE_PRIVATE); fos.write(imgBase64Str.getBytes("utf-8")); fos.flush(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:Main.java
public static Uri getAllCallLogs(ContentResolver cr, Uri internal, Context context, String timeStamp) { SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yy HH:mm"); String[] callLogArray = new String[3]; String strOrder = android.provider.CallLog.Calls.DATE + " DESC"; Uri callUri = Uri.parse("content://call_log/calls"); Cursor cur = cr.query(callUri, null, null, null, strOrder); FileOutputStream fOut = null; try {// w w w . j a va 2 s . co m fOut = context.openFileOutput("call_logs_" + timeStamp + ".txt", Context.MODE_PRIVATE); } catch (FileNotFoundException e) { e.printStackTrace(); } OutputStreamWriter osw = new OutputStreamWriter(fOut); while (cur.moveToNext()) { callLogArray[0] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.NUMBER)); callLogArray[1] = cur.getString(cur.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME)); int thirdIndex = cur.getColumnIndex(android.provider.CallLog.Calls.DATE); long seconds = cur.getLong(thirdIndex); String dateString = formatter.format(new Date(seconds)); callLogArray[2] = dateString; writeToOutputStreamArray(callLogArray, osw); } try { osw.close(); } catch (IOException e) { e.printStackTrace(); } return internal; }
From source file:Main.java
@SuppressWarnings("unchecked") public static List<Parcelable> readParcelableList(Context context, String fileName, ClassLoader classLoader) { List<Parcelable> results = null; FileInputStream fis = null;/*from w w w . j ava2s.c o m*/ ByteArrayOutputStream bos = null; try { fis = context.openFileInput(fileName); if (fis != null) { bos = new ByteArrayOutputStream(); byte[] b = new byte[4096]; int bytesRead; while ((bytesRead = fis.read(b)) != -1) { bos.write(b, 0, bytesRead); } byte[] data = bos.toByteArray(); Parcel parcel = Parcel.obtain(); parcel.unmarshall(data, 0, data.length); parcel.setDataPosition(0); results = parcel.readArrayList(classLoader); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); results = null; } finally { if (fis != null) try { fis.close(); } catch (IOException e) { e.printStackTrace(); } if (bos != null) try { bos.close(); } catch (IOException e) { e.printStackTrace(); } } return results; }
From source file:Main.java
public static List<String> createListFromFile(File f) { List<String> retList = new ArrayList<String>(); FileInputStream fis;/*from www . ja v a2 s. co m*/ BufferedReader br; try { fis = new FileInputStream(f); InputStreamReader isr = new InputStreamReader(fis); br = new BufferedReader(isr); String nStr; nStr = br.readLine(); while (nStr != null) { retList.add(nStr); nStr = br.readLine(); } br.close(); fis.close(); } catch (FileNotFoundException e) { logger.severe(e.toString()); e.printStackTrace(); } catch (IOException e) { logger.severe(e.toString()); e.printStackTrace(); } return retList; }
From source file:Main.java
/** * Read certain text file./*from ww w . j a v a2s . co m*/ */ public static String readFile(File file) { String result = ""; try { result = readFile(new FileInputStream(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } return result; }
From source file:Main.java
public static ByteArrayOutputStream loadXMLFromFile(String fileName) { try {/*from w ww. j a va2 s. c o m*/ ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = builder.parse(new FileInputStream(fileName)); transfer(doc, outputStream); return outputStream; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (TransformerFactoryConfigurationError e) { e.printStackTrace(); } catch (TransformerException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static int[] readBin83PtIndex(String dir, String fileName) { int i = 0;// w w w .ja v a 2 s . c om int x = 0; int[] tab = new int[83]; File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); } DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(inFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { x = in.readInt(); while (true) { tab[i] = x; i++; x = in.readInt(); } } catch (EOFException e) { try { Log.d(TAG, "close"); in.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { //free ressources Log.d(TAG, "close"); in.close(); } catch (IOException e) { e.printStackTrace(); } } } return tab; }
From source file:Main.java
public static float[] readBinTextureArray(String dir, String fileName, int size) { float x;/*from ww w . ja v a2 s . c o m*/ int i = 0; float[] tab = new float[size]; File sdLien = Environment.getExternalStorageDirectory(); File inFile = new File(sdLien + File.separator + dir + File.separator + fileName); Log.d(TAG, "path of file : " + inFile); if (!inFile.exists()) { throw new RuntimeException("File doesn't exist"); } DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(inFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { x = in.readFloat(); // convert here for OpenGl while (true) { tab[i] = x / 255.0f; i++; x = in.readFloat(); // convert here for OpenGl } } catch (EOFException e) { try { Log.d(TAG, "close"); in.close(); } catch (IOException e1) { e1.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } finally { if (in != null) { try { //free ressources Log.d(TAG, "close"); in.close(); } catch (IOException e) { e.printStackTrace(); } } } return tab; }