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[] readBinShapeArray(String dir, String fileName, int size) {
    float x;/*from   www  . j  a v a  2s  . co  m*/
    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 {
        //read first x
        x = in.readFloat();
        while (true) {
            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 String getProperty(String path, String key) {
    Properties prop = new Properties();
    InputStream input = null;//from   ww w  .j  a v a2s . c  om
    String output = "";
    try {
        input = new FileInputStream(path);
        prop.load(input);
        output = prop.getProperty(key, "");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
    return output;
}

From source file:Main.java

/**
 * Read the featureVector_Shape.dat file.
 * Build the double array and return it.
 * k : number of rows//  ww w  .j  a v a  2s  .com
 * n : number of columns
 */
public static float[][] readBinFloatDoubleArray(String dir, String fileName, int k, int n) {
    float[][] array2D = new float[k][n];
    float x;
    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 {
        for (int i = 0; i < k; i++) {
            for (int j = 0; j < n; j++) {
                x = in.readFloat();
                array2D[i][j] = x;
            }
        }
    } 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 array2D;
}

From source file:Main.java

private static byte[] MD5EncodeFileByte(File filename) {
    if (filename != null) {
        int i;/* www  .j  a v a  2  s  . c  om*/
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
        byte[] data = new byte[4096];
        FileInputStream fis;
        try {
            fis = new FileInputStream(filename);
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
            return null;
        }
        while (true) {
            try {
                i = fis.read(data);
                if (i != -1) {
                    md.update(data, 0, i);
                } else {
                    fis.close();
                    return md.digest();
                }
            } catch (IOException e) {
                e.printStackTrace();
                try {
                    fis.close();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
                return null;
            }
        }
    }
    return null;
}

From source file:Main.java

public static List<String> getSDCardPaths() {
    List<String> list = new ArrayList<String>();
    BufferedReader br = null;//from  w  w w .  j ava  2 s  .com
    try {
        Runtime runtime = Runtime.getRuntime();
        Process proc = runtime.exec("mount");
        InputStream is = proc.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        String line;
        br = new BufferedReader(isr);
        while ((line = br.readLine()) != null) {
            if (line.contains("secure"))
                continue;
            if (line.contains("asec"))
                continue;

            if (line.contains("fat")) {
                String columns[] = line.split(" ");
                if (columns != null && columns.length > 1) {
                    list.add(columns[1]);
                }
            } else if (line.contains("fuse")) {
                String columns[] = line.split(" ");
                if (columns != null && columns.length > 1) {
                    list.add(columns[1]);
                }
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
            }
        }
    }
    return list;
}

From source file:Main.java

/**
 * Reads in model 83 points and returns a double array float containing the
 * coordinates x & y.//from  w  ww . ja  v  a2s  . c om
 */
public static float[][] readBinModel83Pt2DFloat(String dir, String fileName) {
    float[][] array2D = new float[83][2];
    float x;
    int i = 0;
    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 {
        while (true) {
            x = in.readFloat();
            array2D[i][0] = x;
            x = in.readFloat();
            array2D[i][1] = x;
            i++;
        }
    } 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 array2D;
}

From source file:Main.java

public static File saveBitmapToExternal(Bitmap bitmap, String targetFileDirPath) {
    if (bitmap == null || bitmap.isRecycled()) {
        return null;
    }// w  w  w  .j av a2s  . c o  m

    File targetFileDir = new File(targetFileDirPath);
    if (!targetFileDir.exists() && !targetFileDir.mkdirs()) {
        return null;
    }

    File targetFile = new File(targetFileDir, UUID.randomUUID().toString());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(targetFile);
        baos.writeTo(fos);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } finally {
        try {
            baos.flush();
            baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (fos != null) {
                fos.flush();
                fos.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    return targetFile;
}

From source file:Main.java

/**
 * Reads in model 83 points and returns a double array float containing the
 * coordinates x & y.//from  w w  w  . ja v a  2  s. c om
 */
public static float[][][] readBinSFSV(String dir, String fileName) {
    float[][][] array3D = new float[60][83][3];
    float x;
    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 {
        for (int k = 0; k < 3; k++) {
            for (int j = 0; j < 83; j++) {
                for (int i = 0; i < 60; i++) {
                    x = in.readFloat();
                    array3D[i][j][k] = x;
                }
            }
        }
    } 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 array3D;
}

From source file:ispyb.common.util.IspybFileUtils.java

public static byte[] getFile(String filePath) throws IOException {
    File file = new File(filePath);
    if (file.exists()) {
        byte[] fileInBytes = new byte[(int) file.length()];
        InputStream inputStream = null;
        try {//from www  .ja v  a  2s.  com
            inputStream = new FileInputStream(file);
            inputStream.read(fileInBytes);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            throw e;
        } finally {
            inputStream.close();
        }
        return fileInBytes;
    }
    return null;
}

From source file:Main.java

/**
 * Method to save audio file to SD card//from   www  . ja  v a 2 s. c  o  m
 * @param course_title, title of course
 * @param format, the file format, for example .mp3, .txt
 */
public static boolean copyToStorage(File source_file, String course_title, String format) {

    File output_file = getEmptyFileWithStructuredPath(course_title, format);

    try {
        byte[] buffer = new byte[4096];
        int bytesToHold;

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(source_file));
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(output_file));

        while ((bytesToHold = bis.read(buffer)) != -1) {
            bos.write(buffer, 0, bytesToHold);
        }

        bos.flush();
        bos.close();

        return true;

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

    return false;
}