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:be.ac.ua.comp.scarletnebula.core.KeyManager.java

/**
 * Creates a new key from the contents of the key in a string.
 * /*w w w  . jav  a 2  s.  c om*/
 * @param providerName
 *            Name of the provider
 * @param keyname
 *            Name of the key
 * @param key
 *            Contents of the key
 */
public static void addKey(final String providerName, final String keyname, final File key) {

    if (assureDirectory(providerName) == null) {
        return;
    }

    try {
        Utils.copyFile(key, new File(getKeyFilename(providerName, keyname)));
    } catch (final FileNotFoundException e) {
        e.printStackTrace();
    } catch (final IOException e) {
        e.printStackTrace();
    }
}

From source file:com.baran.file.FileOperator.java

public static byte[] readFileToBinaryArray(File file) {
    byte[] bin = null;
    try {/*from w ww .  j  a v  a2 s .c o m*/
        InputStream is = new FileInputStream(file);

        // commons-io-2.4.jar
        bin = IOUtils.toByteArray(is);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return bin;
}

From source file:Main.java

public static void takeScreenshot(String where, String name, View v) {

    // image naming and path to include sd card appending name you choose
    // for file/*from w  w w. ja v  a 2  s.co  m*/
    String mPath = where + "/" + name;

    // create bitmap screen capture
    Bitmap bitmap;
    View v1 = v.getRootView();
    v1.setDrawingCacheEnabled(true);
    bitmap = Bitmap.createBitmap(v1.getDrawingCache());
    v1.setDrawingCacheEnabled(false);

    OutputStream fout = null;
    File imageFile = new File(mPath);

    try {
        fout = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.PNG, 90, fout);
        fout.flush();
        fout.close();

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

}

From source file:com.model.database.Databases.java

public static HashMap<String, String[]> getDbInfo() {

    HashMap<String, String[]> infoMap = new HashMap<String, String[]>();
    try {/*ww w . ja  v  a  2  s.c o m*/
        path = Databases.class.getProtectionDomain().getCodeSource().getLocation().getPath();
        BufferedReader reader = new BufferedReader(
                new FileReader(path + "../../src/main/resources/admin/resources/dbInfo.csv"));
        String[] keys = reader.readLine().trim().split(",");
        ArrayList<String[]> elem = new ArrayList<String[]>();
        String line = reader.readLine();
        while (line != null && !line.equals("")) {
            elem.add(line.trim().split(","));
            line = reader.readLine();
        }
        Collections.sort(elem, new Comparator<String[]>() {
            public int compare(String[] l1, String[] l2) {
                return Integer.parseInt(l1[0]) - Integer.parseInt(l2[0]);
            }
        });
        reader.close();
        for (int i = 0; i < keys.length; i++) {
            String[] tmp = new String[elem.size()];
            for (int j = 0; j < elem.size(); j++) {
                tmp[j] = elem.get(j)[i];
            }
            infoMap.put(keys[i], tmp);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println("The database size is : " + String.valueOf(infoMap.get("databaseIndex").length));
    return infoMap;
}

From source file:Main.java

public static Bitmap saveBitmapToFile(Activity activity, Bitmap bitmap) {
    String mPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).toString();
    File imageFile = new File(mPath);
    boolean create = imageFile.mkdirs();
    boolean canWrite = imageFile.canWrite();
    Calendar cal = Calendar.getInstance();
    String date = cal.get(Calendar.YEAR) + "-" + cal.get(Calendar.MONTH) + "-" + cal.get(Calendar.DATE);

    String filename = null;//from ww  w .  j  a v  a2 s . c  o  m
    int i = 0;
    while (imageFile.exists()) {
        i++;
        filename = date + "_mandelbrot" + i + ".png";
        imageFile = new File(mPath, filename);
        boolean canWrite2 = imageFile.canWrite();

    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        /*resultB*/bitmap.compress(CompressFormat.PNG, 90, bos);
        byte[] bitmapdata = bos.toByteArray();

        //write the bytes in file
        FileOutputStream fos = new FileOutputStream(imageFile);
        fos.write(bitmapdata);
        fos.flush();
        fos.close();

        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        intent.setData(Uri.fromFile(imageFile));
        activity.sendBroadcast(intent);

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

From source file:com.google.code.uclassify.client.examples.TrainExample.java

/**
 * Process command line options and call the service.
 * //w  ww  .  j a  v a 2 s  . c  o m
 * @param line the line
 * @param options the options
 */
private static void processCommandLine(CommandLine line, Options options) {
    if (line.hasOption(HELP_OPTION)) {
        printHelp(options);
    } else if (line.hasOption(WRITE_KEY)) {
        final String writeKeyValue = line.getOptionValue(WRITE_KEY);

        final UClassifyClientFactory factory = UClassifyClientFactory.newInstance(null, writeKeyValue);
        final UClassifyClient client = factory.createUClassifyClient();

        if (line.hasOption(CLASSIFIER) && line.hasOption(TEXT)) {
            String classifier = line.getOptionValue(CLASSIFIER);
            String textFile = line.getOptionValue(TEXT);
            System.out.println("Classifying classifier:" + classifier);
            try {
                client.train(classifier, new FileInputStream(textFile));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
            System.out.println("Training complete.");
            //             List<ClassInformation> informations = client.getInformation(classifier);
            //             printResult(informations);
        }
    } else {
        printHelp(options);
    }
}

From source file:com.sec.ose.osi.ui.frm.main.identification.autoidentify.SPDXPackageInfoParser.java

public static SPDXPackageDTO getSPDXPackageInfo(String filePath) {
    SPDXPackageDTO tempSPDXPackageInfo = null;

    BufferedReader br = null;/*from   w w w .  j  a  v  a 2s.  c  o m*/
    try {
        br = new BufferedReader(new FileReader(filePath));
        String tmp = null;
        boolean fCreatorSection = false;
        boolean fPackageNameSection = false;
        while ((tmp = br.readLine()) != null) {
            if (tmp.contains(SPDXPackageInfoParser.CreationInfoTag)) {
                fCreatorSection = true;
                if (tempSPDXPackageInfo == null)
                    tempSPDXPackageInfo = new SPDXPackageDTO();
                while ((tmp = br.readLine()) != null) {
                    if (tmp.contains("Person:")) {
                        tmp = tmp.substring(tmp.indexOf("Person:") + "Person: ".length(),
                                tmp.indexOf("</creator>"));
                        tempSPDXPackageInfo.setPerson(tmp);
                    } else if (tmp.contains("Organization:")) {
                        tmp = tmp.substring(tmp.indexOf("Organization:") + "Organization: ".length(),
                                tmp.indexOf("</creator>"));
                        tempSPDXPackageInfo.setOrganization(tmp);
                    } else if (tmp.contains("<created>")) {
                        tmp = tmp.substring(tmp.indexOf("<created>") + "<created>".length(),
                                tmp.indexOf("</created>"));
                        tempSPDXPackageInfo.setCreated(tmp);
                    } else if (tmp.contains("</rdf:Description>")) {
                        break;
                    }
                }
            }
            if ((tmp != null) && (tmp.contains(SPDXPackageInfoParser.PackageNameTag))) {
                fPackageNameSection = true;
                if (tempSPDXPackageInfo == null)
                    tempSPDXPackageInfo = new SPDXPackageDTO();
                tmp = tmp.substring(tmp.indexOf("<name>") + "<name>".length(), tmp.indexOf("</name>"));
                tempSPDXPackageInfo.setName(tmp);
            }
            if (fCreatorSection && fPackageNameSection) {
                break;
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                log.debug(e);
            }
        }
    }

    return tempSPDXPackageInfo;
}

From source file:Main.java

@SuppressLint("NewApi")
public static Bitmap decodeSampledBitmap(Uri uri, int reqWidth, int reqHeight, Activity act) {

    // First decode with inJustDecodeBounds=true to check dimensions
    InputStream is;/*from  w  ww .  j  a  va  2  s  .  c o m*/
    try {
        is = act.getApplicationContext().getContentResolver().openInputStream(uri);
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        BitmapFactory.decodeStream(is, null, options);
        is.close(); //consider use is.mark and is.reset instead [TODO]

        // Calculate inSampleSize
        options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

        // Decode bitmap with inSampleSize set
        //open input stream again
        is = act.getApplicationContext().getContentResolver().openInputStream(uri);
        options.inJustDecodeBounds = false;
        Bitmap ret = BitmapFactory.decodeStream(is, null, options);
        is.close();
        return ret;
    } catch (FileNotFoundException e) {
        Log.v(TAG, "File not found:" + uri.toString());
        e.printStackTrace();
    } catch (IOException e) {
        Log.v(TAG, "I/O exception with file:" + uri.toString());
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static void writeToExternalFile(String data, String logTag, String fileName) {

    if (!isExternalStorageWritable()) {
        Log.e(logTag, "failed to find external storage");
    } else {/*from  w  ww  .  j a  v a  2  s  . c  o  m*/
        File path = Environment.getExternalStorageDirectory();
        File dir = new File(path.getAbsolutePath() + "/SDNController");
        if (!dir.isDirectory()) {
            if (!dir.mkdirs()) {
                Log.e(logTag, "sdn directory can not be created");
                return;
            }
        }

        File file = new File(dir, fileName);
        try {
            FileOutputStream f = new FileOutputStream(file, true);
            PrintWriter pw = new PrintWriter(f);
            pw.println(data);
            pw.flush();
            pw.close();
            f.close();
        } catch (FileNotFoundException e) {
            Log.e(logTag, "can not find indicated file");
            e.printStackTrace();
        } catch (IOException e) {
            Log.e(logTag, "failed to write SDNController/result.txt");
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static Uri getImageUrlWithAuthority(Context context, Uri uri) {
    InputStream is = null;// w w w.  ja va2s  .c om

    try {

        if (uri.getAuthority() == null) {
            return null;
        } else if (uri.getAuthority() != null) {
            try {
                is = context.getContentResolver().openInputStream(uri);
                Bitmap bmp = BitmapFactory.decodeStream(is);

                bitmapResult = bmp;
                return writeToTempImageAndGetPathUri(context, bmp);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}