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 byte[] File2byte(String filePath) {
    byte[] buffer = null;
    try {/*from   ww  w.j a  v a2  s .  c  o  m*/
        File file = new File(filePath);
        FileInputStream fis = new FileInputStream(file);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        int n;
        while ((n = fis.read(b)) != -1) {
            bos.write(b, 0, n);
        }
        fis.close();
        bos.close();
        buffer = bos.toByteArray();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return buffer;
}

From source file:Main.java

public static Bitmap getBitmapByPath(String filePath, BitmapFactory.Options opts) {
    FileInputStream fis = null;// w w w . j a v  a  2 s .co m
    Bitmap bitmap = null;
    try {
        File file = new File(filePath);
        fis = new FileInputStream(file);
        bitmap = BitmapFactory.decodeStream(fis, null, opts);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
    } finally {
        try {
            fis.close();
        } catch (Exception e) {
        }
    }
    return bitmap;
}

From source file:Main.java

public static String readAssertsTextContent(Context context, String filename) {
    InputStream is = null;/* w  ww.java  2  s .c o  m*/
    try {
        is = context.getResources().getAssets().open(filename);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        StringBuilder sb = new StringBuilder();
        while (reader.ready())
            sb.append(reader.readLine());
        return sb.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:Main.java

public static void getParam(String filename) {
    Properties props = new Properties();
    File file = new File(filename);
    try {/*from ww  w.j  a v  a 2  s.c  om*/
        props.load(new FileInputStream(file));
        //         String value = props.getProperty(key);
        driver = props.getProperty("driver");
        url = props.getProperty("url");
        dbUser = props.getProperty("dbUser");
        dbPwd = props.getProperty("dbPwd");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

/**
 * parse a certificate file into ArrayList of certificates
 *//*from w w  w .j av  a  2  s.co m*/
public static ArrayList<Certificate> readCertificate(File f) throws CertificateException {
    ArrayList<Certificate> certs = new ArrayList<Certificate>();
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    BufferedInputStream in;
    try {
        in = new BufferedInputStream(new FileInputStream(f));
        while (in.available() > 0) {
            Certificate cert = cf.generateCertificate(in);
            certs.add(cert);
        }
        in.close();
        return certs;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static boolean byte2file(byte[] bytes, File file) {
    BufferedOutputStream bos = null;
    FileOutputStream fos = null;/*from w  w w.  j  a  v  a2 s  . c  o  m*/
    try {
        fos = new FileOutputStream(file);
        bos = new BufferedOutputStream(fos);
        bos.write(bytes);
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } finally {
        try {
            if (bos != null)
                bos.close();
            if (fos != null)
                fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void saveToFile(Bitmap... bitmaps) {
    int i = 0;// w w  w  .j  a v a  2  s. c  o m
    for (Bitmap bitmap : bitmaps) {
        String path = Environment.getExternalStorageDirectory().getPath();
        File file = new File(path + "/" + (i++) + ".jpg");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        bitmap.compress(CompressFormat.JPEG, 100, fos);
        try {
            fos.flush();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void saveMyBitmap3(String bitName, Bitmap mBitmap) throws IOException {
    String myJpgPath = Environment.getExternalStorageDirectory() + "/pepper/" + "3.png";
    File tmp = new File("/sdcard/pepper/");
    if (!tmp.exists()) {
        tmp.mkdir();//from   w  w w . java  2 s. com
    }
    File f = new File(myJpgPath);
    f.createNewFile();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeFile(String content, String path) {
    FileOutputStream fos = null;/* w w  w.j  a va2  s  .  c o  m*/
    BufferedWriter bw = null;
    try {
        File file = new File(path);
        fos = new FileOutputStream(file);
        bw = new BufferedWriter(new OutputStreamWriter(fos, "GB2312"));
        bw.write(content);
    } catch (FileNotFoundException fnfe) {
        fnfe.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } finally {
        try {
            if (bw != null)
                bw.close();
            if (fos != null)
                fos.close();
        } catch (IOException ie) {
        }
    }
}

From source file:Main.java

public static void saveMyBitmap2(String bitName, Bitmap mBitmap) throws IOException {
    String myJpgPath = Environment.getExternalStorageDirectory() + "/pepper/" + "2.png";
    File tmp = new File("/sdcard/pepper/");
    if (!tmp.exists()) {
        tmp.mkdir();/*  w ww  .ja  v  a  2 s.c  o  m*/
    }
    File f = new File(myJpgPath);
    f.createNewFile();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.PNG, 100, fOut);
    try {
        fOut.flush();
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}