Example usage for java.io FileNotFoundException printStackTrace

List of usage examples for java.io FileNotFoundException printStackTrace

Introduction

In this page you can find the example usage for java.io FileNotFoundException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

public static Uri getAllContacts(ContentResolver cr, Uri internal, Context context, String timeStamp) {

    String[] contactsArray = new String[2];
    Uri contactsUri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;

    Cursor cur = cr.query(contactsUri, null, null, null, null);

    FileOutputStream fOut = null;
    try {/*from  w  w w  .  ja  v  a2 s  .c o  m*/
        fOut = context.openFileOutput("contacts_" + timeStamp + ".txt", Context.MODE_PRIVATE);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    OutputStreamWriter osw = new OutputStreamWriter(fOut);

    while (cur.moveToNext()) {
        contactsArray[0] = cur
                .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME))
                .toString();
        contactsArray[1] = cur
                .getString(cur.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.NUMBER));

        writeToOutputStreamArray(contactsArray, osw);
    }

    try {
        osw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return internal;
}

From source file:Main.java

public static Object getObjectFromFile(String filePath) {
    FileInputStream freader;/*from w w  w .  j a  v  a 2s.  c o m*/
    Object ret = null;
    try {
        freader = new FileInputStream(filePath);
        ObjectInputStream objectInputStream = new ObjectInputStream(freader);
        ret = objectInputStream.readObject();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block   
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block   
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block   
        e.printStackTrace();
    }
    return ret;
}

From source file:Main.java

public static String saveToPrivateFile(Activity activity, String filename, Bitmap bmp) {
    FileOutputStream fos;/*w  w  w. ja va2s .  c o  m*/
    try {
        fos = activity.openFileOutput(filename, Context.MODE_PRIVATE);
        bmp.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.close();

        return filename;

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "";
    }

}

From source file:Main.java

public static long getFileSizes(File f) {
    FileInputStream fis = null;//from w  w w  .j  a  va 2s  .  com
    try {
        fis = new FileInputStream(f);
        return fis.available();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    return -1;
}

From source file:Main.java

public static void savePhotoToSDCard(Bitmap photoBitmap, String path, String photoName) {
    File dir = new File(path);
    if (!dir.exists()) {
        dir.mkdirs();//from ww  w  .  j  a v  a  2  s.c o m
    }
    File photoFile = new File(path, photoName);
    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(photoFile);
        if (photoBitmap != null) {
            if (photoBitmap.compress(Bitmap.CompressFormat.PNG, 100, fileOutputStream)) {
                fileOutputStream.flush();
            }
        }
    } catch (FileNotFoundException e) {
        photoFile.delete();
        e.printStackTrace();
    } catch (IOException e) {
        photoFile.delete();
        e.printStackTrace();
    } finally {
        try {
            fileOutputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static Document parseFile(final File aFile, final Properties props)
        throws SAXException, ParserConfigurationException {
    InputStream input = null;//from   ww w.jav a  2s. c  om
    try {
        input = new FileInputStream(aFile);
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
        return null;
    }
    return parse(input, props);
}

From source file:Main.java

public static BitmapDrawable getBitmapDrawableFromUrl(Resources res, URL trueUrl,
        BitmapFactory.Options mOptions) throws Exception {
    Bitmap bitmap = null;//from w ww.j a va 2s.co  m
    FileInputStream mFS = null;
    try {
        mFS = new FileInputStream(trueUrl.getPath());
        bitmap = BitmapFactory.decodeFileDescriptor(mFS.getFD(), null, mOptions);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (mFS != null) {
            mFS.close();
        }
    }
    return new BitmapDrawable(res, bitmap);
}

From source file:Main.java

public static void saveBitmap(Bitmap bitmap, String descPath) {
    File file = new File(descPath);
    if (!file.getParentFile().exists()) {
        file.getParentFile().mkdirs();//from w  ww  .j ava 2s  .  c om
    }
    if (!file.exists()) {
        try {
            bitmap.compress(CompressFormat.JPEG, 30, new FileOutputStream(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (null != bitmap) {
        bitmap.recycle();
        bitmap = null;
    }
}

From source file:Main.java

public static String saveBitmapToFile(File dir, String name, Bitmap bitmap, String picKind) {
    File f = new File(dir, name + picKind);
    try {//from   w w  w  .ja  v  a 2s  . co m
        f.createNewFile();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    CompressFormat format = CompressFormat.JPEG;
    if (picKind != null && picKind.equalsIgnoreCase(".png")) {
        format = CompressFormat.PNG;
    }
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
        bitmap.compress(format, 100, fOut);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        if (fOut != null) {
            fOut.flush();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        if (fOut != null) {
            fOut.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    bitmap.recycle();
    bitmap = null;
    return f.getAbsolutePath();
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Parcelable readParcelable(Context context, String fileName, ClassLoader classLoader) {
    Parcelable parcelable = null;//from  www.j  a  v  a2 s . c  om
    FileInputStream fis = null;
    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);
            parcelable = parcel.readParcelable(classLoader);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
        parcelable = 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 parcelable;
}