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 void saveBitmap(Bitmap bm, String picName) {
    try {/*  w w w .  j a  v a 2  s  .co  m*/
        if (!isFileExist("")) {
            createSDDir("");
        }
        File f = new File(SDPATH, picName);
        if (f.exists()) {
            f.delete();
        }
        FileOutputStream out = new FileOutputStream(f);
        bm.compress(Bitmap.CompressFormat.JPEG, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String readTextFile(File file) {
    if (!file.exists()) {
        return null;
    }//from   w w w  . j a v  a 2s  .  c o m

    StringBuilder sb = new StringBuilder();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

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

    return sb.toString();
}

From source file:Main.java

public static int getCurrCpuFreq() {
    int result = 0;
    FileReader fr = null;/*from  w  w w .  j a v a  2s  . com*/
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoCurFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

public static void saveJpegFile(String fileName, Bitmap bitmap) {
    // file/*  w  w  w  .  ja  va2 s. co  m*/
    File file = new File(extStorageDirectory, fileName + ".jpg");
    File fileDirectory = new File(extStorageDirectory);
    if (!fileDirectory.exists()) {
        fileDirectory.mkdir();
    }
    OutputStream outStream = null;
    try {
        outStream = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outStream);
        outStream.flush();
        outStream.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void write(Context context, String fileName, String content) {
    if (content == null) {
        content = "";
    }/* w w  w  .  j a v a  2 s  .  co m*/
    try {
        FileOutputStream fs = context.openFileOutput(fileName, Context.MODE_PRIVATE);
        fs.write(content.getBytes());
        fs.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static int getMinCpuFreq() {
    int result = 0;
    FileReader fr = null;/* w w  w . j  a va  2  s .c om*/
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoMinFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

public static boolean insertMediaStore(Context context, File file, String imageName) {
    if (context == null || file == null || !file.exists()) {
        return false;
    }/*from  w  w w  .  j  a v  a2  s.c  o  m*/

    if (TextUtils.isEmpty(imageName)) {
        imageName = SystemClock.currentThreadTimeMillis() + PNG;
    }
    try {

        MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), imageName,
                null);
        // String imagePath =
        // MediaStore.Images.Media.insertImage(getContentResolver(),
        // bitmap, "", "");

        context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    }

    return true;

}

From source file:Main.java

public static int getMaxCpuFreq() {
    int result = 0;
    FileReader fr = null;/*  w w w  .j  a v  a  2s  .  c  o  m*/
    BufferedReader br = null;
    try {
        fr = new FileReader(kCpuInfoMaxFreqFilePath);
        br = new BufferedReader(fr);
        String text = br.readLine();
        result = Integer.parseInt(text.trim());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fr != null)
            try {
                fr.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return result;
}

From source file:Main.java

public static void saveBitmap(Bitmap bm, String picName) {
    try {/*ww w  .  j  a  va2 s . 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, 100, out);
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static File saveFile(InputStream is, String destDir, String fileName) throws IOException {
    File dir = new File(destDir);
    fileName = getString(fileName);/*  w  w  w.  j ava 2s.c  om*/
    if (!dir.exists()) {
        dir.mkdirs();
    }
    BufferedInputStream bis = new BufferedInputStream(is);
    BufferedOutputStream bos = null;
    try {
        File saveFile = new File(destDir, fileName);
        bos = new BufferedOutputStream(new FileOutputStream(saveFile));
        int len = -1;
        while ((len = bis.read()) != -1) {
            bos.write(len);
            bos.flush();
        }
        bos.close();
        bis.close();
        return saveFile;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}