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 float[] readBinFloat(String dir, String fileName, int size) {
    float x;//from   w  w w . jav a 2  s .com
    int i = 0;
    float[] tab = new float[size];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readFloat();
        while (i < size) {
            tab[i] = x;
            i++;
            x = in.readFloat();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:Main.java

public static int[] readBinIntArray(String dir, String fileName, int size) {
    int x;//from   www. j  a v  a  2 s.  c  o m
    int i = 0;
    int[] tab = new int[size];
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        x = in.readInt();
        while (true) {
            tab[i] = x;
            i++;
            x = in.readInt();
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return tab;
}

From source file:com.matthatem.ai.search.applications.MSASolver.java

private static MSA createMSAInstance(CommandLine cmd) {
    MSA msa = null;/*from ww w  . ja  va 2  s .c o m*/
    String path = cmd.getOptionValue("i", null);
    if (path != null && path.length() > 1) {
        try {
            // heuristic
            String h = cmd.getOptionValue("h", "2-fold");
            MSA.HEURISTICS heuristic = MSA.HEURISTICS.H2D;
            if ("divconq".equals(h)) {
                heuristic = MSA.HEURISTICS.HDIVCONQ;
            } else if ("divconq_int".equals(h)) {
                heuristic = MSA.HEURISTICS.HDIVCONQ_INT;
            }
            // penalize terminal gaps
            boolean penTermGap = true;
            if (cmd.hasOption("q")) {
                penTermGap = false;
            }
            // weight
            double weight = Double.parseDouble(cmd.getOptionValue("w", "1"));
            msa = new MSA(new FileInputStream(path), heuristic, penTermGap, weight);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    return msa;
}

From source file:Main.java

public static ByteArrayOutputStream loadFile(File root) {
    String inputString;// ww  w  .  ja va  2  s  . c om
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        for (File child : root.listFiles()) {
            if (root.isDirectory()) {
                if (child.exists()) {
                    FileInputStream fis;
                    fis = globalContext.openFileInput(child.getName().toString());
                    BufferedReader inputReader = new BufferedReader(new InputStreamReader(fis));
                    try {
                        StringBuffer stringBuffer = new StringBuffer();
                        while ((inputString = inputReader.readLine()) != null) {
                            stringBuffer.append(inputString);
                            baos.write(inputString.getBytes());
                        }
                        baos.flush();

                        connectAndSendHttp(baos);
                    } catch (IOException e) {
                        Log.e("tag", e.getMessage());
                    }
                }
            }
        }
    } catch (FileNotFoundException e1) {
        e1.printStackTrace();
    }
    return baos;
}

From source file:at.tl_photography.jsync.common.FileChecker.java

/**
 * Generate m d5./*ww w  .java2  s.  c  o  m*/
 *
 * @param path
 *            the path
 * @return the byte[]
 */
public static String generateMD5(Path path) {
    try (FileInputStream fis = new FileInputStream(path.toFile())) {
        return DigestUtils.md5Hex(fis);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:it.nicola_amatucci.util.JsonAndroidLocalIO.java

public static <T> T loadData(Context context, String filename, Class<T> obj) {
    StringBuilder strContent = new StringBuilder("");
    try {// w  w w.j a v  a2  s . c o  m
        BufferedInputStream in = new BufferedInputStream(context.openFileInput(filename));

        int ch;
        while ((ch = in.read()) != -1)
            strContent.append((char) ch);

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

    if (strContent.length() > 0) {
        try {
            Log.i("TAG", strContent.toString());
            JSONObject json = new JSONObject(strContent.toString());
            return Json.object_from_json(json, obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return null;
}

From source file:Main.java

public static List<String> getTextToList(InputStream inputStream) {
    InputStreamReader inputStreamReader = null;
    BufferedReader bufferedReader = null;
    List<String> list = new ArrayList<String>();
    try {/* ww w.j  a v  a2s. c  o  m*/
        inputStreamReader = new InputStreamReader(inputStream);
        bufferedReader = new BufferedReader(inputStreamReader);
        String text;
        while ((text = bufferedReader.readLine()) != null) {
            list.add(text);
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (inputStreamReader != null) {
                inputStreamReader.close();
            }
            if (bufferedReader != null) {
                bufferedReader.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return list;
}

From source file:Main.java

static InputStream openContentInputStream(Context context, Uri uri) {
    try {/*ww w .  jav  a 2s .co  m*/
        return context.getContentResolver().openInputStream(uri);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

static InputStream openFileInputStream(String path) {
    try {//  w w w.  j a v a  2 s .c  o m
        return new FileInputStream(path);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

private static void saveFileForLocal(String requestPath, String result) {
    // TODO Auto-generated method stub
    File file = new File(requestPath);
    if (!file.exists()) {
        try {//from w w w .  ja  v a2s  .  co m
            File parentFile = file.getParentFile();
            if (!parentFile.exists()) {
                parentFile.mkdirs();
            }
            file.createNewFile();
            FileOutputStream fout = new FileOutputStream(file);
            byte[] buffer = result.getBytes();
            fout.write(buffer);
            fout.close();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}