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:controllers.oer.NtToEs.java

private static void initMap(String mapFile) {
    try (Scanner s = new Scanner(new File(mapFile))) {
        while (s.hasNextLine()) {
            String[] keyVal = s.nextLine().split("\\s");
            idMap.put(keyVal[0].trim(), keyVal[1].trim());
        }//from   w ww .j  a v a2s. c o  m
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static float[] readBinAverageShapeArray(String dir, String fileName, int size) {
    float x;/* w w  w  .  j ava2s .  c o  m*/
    int i = 0;
    float[] tab = new float[size];

    // theses values was for 64140 points average shape
    //float minX = -90.3540f, minY = -22.1150f, minZ = -88.7720f, maxX = 101.3830f, maxY = 105.1860f, maxZ = 102.0530f;

    // values for average shape after simplification (8489 points)
    float maxX = 95.4549f, minX = -85.4616f, maxY = 115.0088f, minY = -18.0376f, maxZ = 106.7329f,
            minZ = -90.4051f;

    float deltaX = (maxX - minX) / 2.0f;
    float deltaY = (maxY - minY) / 2.0f;
    float deltaZ = (maxZ - minZ) / 2.0f;

    float midX = (maxX + minX) / 2.0f;
    float midY = (maxY + minY) / 2.0f;
    float midZ = (maxZ + minZ) / 2.0f;

    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();
        //Log.d(TAG,"first Vertices = "+x);
        while (true) {

            tab[i] = (x - midX) / deltaX; //rescale x
            i++;

            //read y
            x = in.readFloat();
            tab[i] = (x - midY) / deltaY; //rescale y
            i++;

            //read z
            x = in.readFloat();
            tab[i] = (x - midZ) / deltaZ; //rescale z
            i++;

            //read x
            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 BitmapDrawable getBitmapDrawable(Context context, Uri uri) {
    System.out.println("uri path = " + uri.getPath());
    Bitmap b;//  w w w  .j  a  va 2s  .  c  o m
    try {
        String path = uri.getPath();
        if (mCache.containsKey(path)) {
            BitmapDrawable d = mCache.get(path).get();
            if (d != null) {
                System.out.println("not recycle path = " + uri.getPath());
                return d;
            } else {
                System.out.println("be recycle path = " + uri.getPath());
                mCache.remove(path);
            }
        }
        System.out.println("----->safeDecodeStream start");
        b = safeDecodeStream(context, uri, 60, 60);
        System.out.println("----->safeDecodeStream end");
        final BitmapDrawable bd = new BitmapDrawable(b);
        mCache.put(path, new SoftReference<BitmapDrawable>(bd));
        return bd;
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:com.sarm.lonelyplanet.process.LPUnMarshallerTest.java

@BeforeClass
public static void setUpClass() {

    Properties prop = new Properties();
    logger.info("LPUnMarshallerTest : Commencing loading test properties ...");
    String propFileName = LonelyConstants.testPropertyFile;

    try (InputStream input = new FileInputStream(propFileName)) {

        if (input == null) {
            logger.debug("input Stream for test.properties file : is Null  ");
            throw new FileNotFoundException("property file '" + propFileName + "' not found in the classpath");
        }/*from   www  .j  ava 2 s  .com*/
        prop.load(input);

    } catch (FileNotFoundException ex) {
        logger.debug("FileNotFoundException ");
        ex.printStackTrace();
    } catch (IOException ex) {
        logger.debug(" IOException");
        ex.printStackTrace();
    }
    taxonomyFileName = prop.getProperty(LonelyConstants.propertyTaxonomy);
    targetLocation = prop.getProperty(LonelyConstants.propertyHtmlTarget);
    destinationFileName = prop.getProperty(LonelyConstants.propertyDestination);
    lp = new LPUnMarshaller(taxonomyFileName, destinationFileName, targetLocation, null);

}

From source file:Main.java

private static void CopyFile(String srcPath, String dstPath) {
    FileChannel srcChannel = null;
    FileChannel dstChannel = null;
    try {/*from  w ww. j a v a 2 s  . c  om*/
        // Open files
        srcChannel = (new FileInputStream(srcPath)).getChannel();
        dstChannel = (new FileOutputStream(dstPath)).getChannel();
        // Transfer the data
        dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
        // Close the files
        if (srcChannel != null) {
            srcChannel.close();
        }
        if (dstChannel != null) {
            dstChannel.close();
        }
    } catch (FileNotFoundException ex) {
        Log.i("CopyFile", "File not found " + ex.getMessage());
        ex.printStackTrace();
    } catch (IOException ex) {
        Log.i("CopyFile", "Transfer data error " + ex.getMessage());
        ex.printStackTrace();
    }
}

From source file:com.smash.revolance.ui.model.helper.ArchiveHelper.java

public static File buildArchive(File archive, File... files) throws FileNotFoundException {
    FileOutputStream fos = new FileOutputStream(archive);
    ZipOutputStream zos = new ZipOutputStream(fos);
    int bytesRead;
    byte[] buffer = new byte[1024];
    CRC32 crc = new CRC32();

    for (File file : files) {
        if (!file.exists()) {
            System.err.println("Skipping: " + file);
            continue;
        }//from  w w  w.j a v  a  2 s .  c  om
        BufferedInputStream bis = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(file));
            crc.reset();
            while ((bytesRead = bis.read(buffer)) != -1) {
                crc.update(buffer, 0, bytesRead);
            }

            bis.close();

            // Reset to beginning of input stream
            bis = new BufferedInputStream(new FileInputStream(file));
            String entryPath = FileHelper.getRelativePath(archive.getParentFile(), file);

            ZipEntry entry = new ZipEntry(entryPath);
            entry.setMethod(ZipEntry.STORED);
            entry.setCompressedSize(file.length());
            entry.setSize(file.length());
            entry.setCrc(crc.getValue());
            zos.putNextEntry(entry);
            while ((bytesRead = bis.read(buffer)) != -1) {
                zos.write(buffer, 0, bytesRead);
            }
        } catch (FileNotFoundException e) {

        } catch (IOException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        } finally {
            IOUtils.closeQuietly(bis);
        }
    }
    IOUtils.closeQuietly(zos);
    return archive;
}

From source file:Main.java

public static boolean reloadMapperXml(String spath, String tPath, String name) {
    try {//w ww  . ja v  a  2 s . co m
        String linetext = "";
        String resultMapText = "";
        StringBuffer sbf = new StringBuffer();
        File f = new File(spath + name);
        BufferedReader br = new BufferedReader(new FileReader(f));
        int lineNum = 1;
        while ((linetext = br.readLine()) != null) {
            sbf.append(linetext);
            sbf.append("\r\n");
            if (lineNum == 4) {
                resultMapText = linetext;
            }
            lineNum++;
        }
        br.close();
        String text = sbf.toString();

        if (text.contains("queryPage")) {
            return false;
        }

        int si = text.indexOf("<insert id=\"insert\"");
        int ei = text.indexOf("</insert>");
        String noinsert = text.substring(si, ei + 9);
        text = text.replace(noinsert, "");

        int su = text.indexOf("<update id=\"updateByPrimaryKey\"");
        int eu = text.indexOf("</update>", su);
        if (su > 0 && eu > 0) {
            String noupdate = text.substring(su, eu + 9);
            text = text.replace(noupdate, "");
        }

        text = text.replace("selectByPrimaryKey", "selectById");
        text = text.replace("deleteByPrimaryKey", "deleteById");
        text = text.replace("insertSelective", "insert");
        text = text.replace("updateByPrimaryKeySelective", "updateById");

        int sp = text.indexOf("<select");
        int ep = text.indexOf("</select>");

        String pageSql = "";
        if (sp > 0 && ep > 0) {
            pageSql = text.substring(sp, ep + 9);
        }
        pageSql = pageSql.replace("selectById", "queryPage");
        pageSql = pageSql.substring(0, pageSql.indexOf("where"));
        pageSql = pageSql + "</select>";

        int sc = resultMapText.indexOf("type=");
        if (sc > 0) {
            resultMapText = resultMapText.substring(sc + 6);
        }

        int ec = resultMapText.lastIndexOf("\"");
        if (ec > 0) {
            resultMapText = resultMapText.substring(0, ec);
        }

        pageSql = pageSql.replace("java.lang.Integer", resultMapText);

        text = text.replace("</mapper>", "");
        StringBuffer newSql = new StringBuffer(text);
        newSql.append(pageSql);
        newSql.append("</mapper>");

        saveFile(tPath, name, newSql.toString());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return true;
}

From source file:org.web4thejob.util.L10nUtil.java

public static void logMissingMessage(String code, String defaultValue) {
    File file = new File(System.getProperty("user.home"),
            "w4tj_" + CoreUtil.getUserLocale().toString() + ".log");
    FileWriter out;//from  w  w  w  .  j  ava2 s.  com
    try {
        out = new FileWriter(file, true);
        out.write(code + "=" + defaultValue + System.getProperty("line.separator"));
        out.close();
        // logger.warn("Missiing message: " + code + "=" + defaultValue);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.dev.pygmy.util.Utils.java

/**
 * Saves the current game by serializing it and storing in locally
 * on the device/* ww  w . j  a  va2 s  .  c  om*/
 */
public static void saveGame(PygmyGame game, String path) {
    ObjectOutputStream oos = null;
    try {
        File history = new File(path);
        history.getParentFile().createNewFile();
        FileOutputStream fout = new FileOutputStream(history);
        oos = new ObjectOutputStream(fout);
        oos.writeObject(game);
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (oos != null) {
                oos.flush();
                oos.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}

From source file:com.opengamma.examples.historical.SimulatedHistoricalDataGenerator.java

private static void readFinishValues(Map<Pair<ExternalId, String>, Double> finishValues) {
    CSVReader reader = null;/*  w  w  w . jav a  2 s. c o m*/
    try {
        reader = new CSVReader(new BufferedReader(new InputStreamReader(
                SimulatedHistoricalDataGenerator.class.getResourceAsStream("historical-data.csv"))));
        // Read header row
        @SuppressWarnings("unused")
        String[] headers = reader.readNext();
        String[] line;
        int lineNum = 0;
        while ((line = reader.readNext()) != null) {
            lineNum++;
            if ((line.length == 0) || line[0].startsWith("#")) {
                s_logger.debug("Empty line on {}", lineNum);
            } else if (line.length != NUM_FIELDS) {
                s_logger.error("Invalid number of fields ({}) in CSV on line {}", line.length, lineNum);
            } else {
                String scheme = line[0];
                String identifier = line[1];
                String fieldName = line[2];
                String valueStr = line[3];
                Double value = Double.parseDouble(valueStr);
                ExternalId id = ExternalId.of(scheme, identifier);
                finishValues.put(Pair.of(id, fieldName), value);
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(reader);
    }
}