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 Bitmap GetFromFile(String fileName, String path) {
    String fString = fileName.replaceAll("/", ".");
    File file = new File("/sdcard/OneBus/user/" + path + "/" + fString + ".jpg");
    if (!file.exists()) {
        return null;
    }// w  ww  .  j ava 2  s.c o  m
    try {

        FileInputStream fis = new FileInputStream(file);
        return BitmapFactory.decodeStream(fis);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:Main.java

public static String readFile(String pathname) {
    File file = new File(pathname);
    StringBuilder fileContents = new StringBuilder((int) file.length());
    String lineSeparator = System.getProperty("line.separator");

    try {/*from  www . ja va 2  s  .  co  m*/
        try (Scanner scanner = new Scanner(file)) {
            while (scanner.hasNextLine()) {
                fileContents.append(scanner.nextLine()).append(lineSeparator);
            }
            return fileContents.toString();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static void saveBitmap(Bitmap bitmap, String filePath) {
    File f = new File(filePath);
    if (f.exists()) {
        return;/*from  w w  w .  j  av  a 2s  .co  m*/
    }
    try {
        FileOutputStream out = new FileOutputStream(f);
        bitmap.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 void saveJPGE_After(Context context, Bitmap bitmap, String path) {
    File file = new File(context.getExternalCacheDir() + path);
    try {//from   ww w  . j a  v  a 2  s  . c om
        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();
    }
}

From source file:Main.java

private static byte[] getBytesFromDriveImageUri(Context context, Uri uri) {
    InputStream inputStream = null;
    try {//from  w  w  w . j a  va2 s  .  com
        inputStream = context.getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    Bitmap bmp = BitmapFactory.decodeStream(inputStream);
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);

    return stream.toByteArray();
}

From source file:Main.java

public static String[] GetMountLine(String PartitionName) {
    try {//from   ww  w .j a  va  2 s . c  o  m
        BufferedReader bProcFS = new BufferedReader(new FileReader("/proc/mounts"));
        String readLine = null;
        while ((readLine = bProcFS.readLine()) != null) {
            String[] args = readLine.split(" ");
            if ((args.length > 3) && (args[1].equalsIgnoreCase("/" + PartitionName))) {
                return args;
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static StringBuilder ReadFileToString(String filename) {
    StringBuilder text = new StringBuilder();
    try {/*ww  w  .  j av  a2  s  .com*/
        BufferedReader bProcFS = new BufferedReader(new FileReader(filename));
        String readLine = null;
        while ((readLine = bProcFS.readLine()) != null) {
            text.append(readLine);
            text.append("\n");
        }
        bProcFS.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return text;
}

From source file:Main.java

public static boolean saveBitmapToFile(Bitmap bitmap, String path) {
    File file = new File(path);
    FileOutputStream fOut;//ww w .j a  va 2s  .  c  om
    try {
        fOut = new FileOutputStream(file);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 95, fOut);
        fOut.flush();
        fOut.close();
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;

}

From source file:Main.java

public static Bitmap readBitmapFromFile(Context context, String imageName) {
    Bitmap bitmap = null;//from w w  w  .  ja v  a 2  s .  c o  m
    try {
        //read avatar file
        FileInputStream fileInputStream = context.openFileInput(imageName);
        bitmap = BitmapFactory.decodeStream(fileInputStream);
        fileInputStream.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return bitmap;
}

From source file:Main.java

public static boolean writeBitmapToFile(Bitmap bitmap, String path) {
    FileOutputStream fos = null;//  www .  j  a  va2 s  . c  om
    try {
        fos = new FileOutputStream(path);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        if (fos != null)
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }
    return false;
}