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 copyFileFast(File in, File out) {
    FileChannel filein = null;/*from  ww  w . ja  v a2s.c om*/
    FileChannel fileout = null;
    try {
        filein = new FileInputStream(in).getChannel();
        fileout = new FileOutputStream(out).getChannel();
        filein.transferTo(0, filein.size(), fileout);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        closeIO(filein, fileout);
    }
}

From source file:Main.java

/**
 * Reads content of the file into string buffer
 * @param tempFile instance of java.io.File that points to an actual file on the file system.
 * @return instance of java.lang.StringBuffer
 *///from www  .java  2  s.c o m
public static StringBuffer readFromFile(File tempFile) {
    StringBuffer stringBuffer = new StringBuffer();
    FileInputStream is = null;

    try {
        is = new FileInputStream(tempFile);

        byte[] buffer = new byte[1024];
        int count = 0;

        while ((count = is.read(buffer)) != -1) {
            stringBuffer.append(new String(buffer, 0, count));
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return stringBuffer;
}

From source file:Main.java

public static boolean saveFile(Bitmap bm, String path) {
    if (bm == null || path == null)
        return false;
    File myCaptureFile = new File(path);
    if (myCaptureFile.exists()) {
        myCaptureFile.delete();//ww  w . ja  va 2  s.  com
    }
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
        bm.compress(Bitmap.CompressFormat.JPEG, 80, bos);
        bos.flush();
        bos.close();
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static boolean saveFile(Bitmap bm, String path, Bitmap.CompressFormat format) {
    if (bm == null || path == null)
        return false;
    File myCaptureFile = new File(path);
    if (myCaptureFile.exists()) {
        myCaptureFile.delete();// w  ww.  ja v  a2s .c o  m
    }
    try {
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
        bm.compress(format, 80, bos);
        bos.flush();
        bos.close();
        return true;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

/**
 * @param context//  ww w . j  a v a  2  s  .c  om
 * @param folder   "assets/json/"
 * @param fileName
 * @return
 */
public static final String getString(Context context, String folder, String fileName) {
    if (TextUtils.isEmpty(folder)) {
        folder = JSON_FOLDER;
    }
    StringBuffer stringBuffer = new StringBuffer();
    try {
        //            InputStream abpath = context.getClass().getResourceAsStream(folder + fileName);
        InputStream abpath = context.getClass().getClassLoader().getResourceAsStream(folder + fileName);
        if (abpath == null) {
            return "";
        }
        // BufferedReader bufferedReader = new BufferedReader(new
        // FileReader(
        // new File("file:///android_asset/json/" + fileName)));
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(abpath));
        String str = "";
        while ((str = bufferedReader.readLine()) != null) {
            stringBuffer.append(str);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return stringBuffer.toString();
}

From source file:com.github.consiliens.harv.run.test.TestGson.java

public static IRequestLogRecord getRecord() {
    GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting();
    gsonBuilder.registerTypeAdapter(RequestLogRecord.class, new IRequestLogRecordSerializer());
    gsonBuilder.registerTypeAdapter(RequestLogRecord.class, new IRequestLogRecordDeserializer());
    Gson gson = gsonBuilder.create();/*w  w  w.  jav  a2 s  .c  o  m*/

    String json = null;
    try {
        json = Utils.streamToString(new FileInputStream("data/out.json"));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    return gson.fromJson(json, RequestLogRecord.class);
}

From source file:Main.java

private static void writeStreamToFile(InputStream stream, File file) {
    try {/*from   w  w w.  j  a  va  2  s . c  om*/
        OutputStream output = null;
        try {
            output = new FileOutputStream(file);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
        try {
            try {
                final byte[] buffer = new byte[1024];
                int read;

                while ((read = stream.read(buffer)) != -1)
                    output.write(buffer, 0, read);
                output.flush();
            } finally {
                output.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } finally {
        try {
            stream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static void toTargz(String srcFile, String targetFile) throws IOException {
    File sourceFile = new File(srcFile);
    File target = new File(targetFile);
    FileInputStream in = null;//  ww  w . ja v  a 2  s . c om
    GZIPOutputStream gout = null;
    try {
        in = new FileInputStream(sourceFile);
        gout = new GZIPOutputStream(new FileOutputStream(target));
        byte[] array = new byte[BUFFER_LEN];
        int number = -1;
        while ((number = in.read(array, 0, array.length)) != -1) {
            gout.write(array, 0, number);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (gout != null) {
            try {
                gout.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public static Bitmap loadImageFromStorage(String path) {
    Bitmap bmp = null;/*from  ww w . j  ava2s . c  o m*/
    try {
        File f = new File(path);

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        //BitmapFactory.decodeResource(res, resId, options);
        BitmapFactory.decodeStream(new FileInputStream(f), null, options);

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, 200, 200);

        // Decode bitmap with inSampleSize set
        options.inJustDecodeBounds = false;
        bmp = BitmapFactory.decodeStream(new FileInputStream(f), null, options);
        //BitmapFactory.decodeS
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return bmp;

}

From source file:Main.java

public static synchronized StringBuilder readTempFile(String filename) {
    File tempFile;//w  w w .  java 2s .c  om
    FileInputStream is = null;

    tempFile = new File(filename);

    String strLine = "";
    StringBuilder text = new StringBuilder();

    /** Reading contents of the temporary file, if already exists */
    try {
        is = new FileInputStream(tempFile);
        //            FileReader fReader = new FileReader(tempFile);
        BufferedReader bReader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));

        /** Reading the contents of the file , line by line */
        while ((strLine = bReader.readLine()) != null) {
            text.append(strLine + "\n");
        }

        bReader.close(); //close bufferedreader
        is.close();

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

    return text;

}