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:com.nuvolect.deepdive.util.FileUtil.java

public static String readFile(File file) {

    String fileContents = "";
    StringBuilder sb = new StringBuilder();

    try {/*from ww  w  .  j  a  v  a2 s  . c  o  m*/
        InputStream is = new FileInputStream(file);

        byte[] buffer = new byte[4096];
        int len;
        while ((len = is.read(buffer)) > 0) {

            String s = new String(buffer, 0, len, "UTF-8");
            sb.append(s);
        }
        fileContents = sb.toString();

        if (is != null)
            is.close();
    } catch (FileNotFoundException e) {
        LogUtil.logException(FileUtil.class, e);
    } catch (IOException e) {
        e.printStackTrace();
    }

    return fileContents;
}

From source file:game.utils.Utils.java

public static String readFile(File file) {
    String ret = null;/*  www .ja  v  a2 s  .c o  m*/
    try {
        Scanner scanner = new Scanner(file);
        ret = scanner.useDelimiter("\\Z").next();
        scanner.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return ret;
}

From source file:edu.duke.cabig.c3pr.utils.DaoTestCase.java

/**
 * For Oracle typically it is "C3PR_DEV" (note- upper case). For Postgres - "public". Dont
 * forget to override this depending on your database
 * //from   w  w w. java 2s .  c  om
 * @return
 */
protected static String getSchema() {
    URL url = ClassLoader.getSystemResource("context/datasource.properties");
    Properties p = new Properties();
    try {
        //p.load(new FileInputStream(new File(url.getFile())));
        p.load(url.openStream());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return p.getProperty("datasource.testschema");
}

From source file:info.bitoo.Main.java

static Properties readConfiguration(CommandLine cmd) {
    /*/*from  w  ww  . ja  v a2s.  c o  m*/
     * Read configuration file
     */
    String configFilename = defaultConfigFilename;
    if (cmd.hasOption("c")) {
        configFilename = cmd.getOptionValue("c");
    }

    Properties props = new Properties();
    try {
        FileInputStream fis = new FileInputStream(configFilename);
        props.load(fis);
        fis.close();
        PropertyConfigurator.configure(props);
        logger.debug("Log4j initialized");
    } catch (FileNotFoundException e) {
        System.out.println("Configuration file not found: [" + configFilename + "]");
        e.printStackTrace();
    } catch (IOException e) {
        System.out.println("Bad configuration file: [" + configFilename + "]");
        e.printStackTrace();
    }
    return props;
}

From source file:com.lexmark.saperion.services.GetFileFromSaperionECM.java

/**
 * /*from   www . ja v a2 s . com*/
 * @param ecodedString
 */
public static void decodedBase64(String ecodedString) {
    byte[] data = Base64.decodeBase64(ecodedString);
    // TODO add the file where the image needs to be copied too
    try (OutputStream stream = new FileOutputStream("C:/Users/Aditya/Desktop/abc.PNG")) {
        stream.write(data);
    } catch (FileNotFoundException e) {
        System.err.println("File location not found for the file to be written");
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String readAM(String xml_path) {
    String result = "";
    if (xml_path == null || !(new File(xml_path)).getName().equals(AM_XML)) {
        return result;
    }/*  w w  w .j a v  a2  s . co m*/

    try {
        InputStream inputStream = new FileInputStream(xml_path);
        result = readAM(inputStream);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    return result;
}

From source file:com.wordnik.swagger.codegen.util.FileUtil.java

private static boolean copyStream(final InputStream is, final File f) {
    try {/*from  w  ww  .  j a  va 2 s.c om*/
        return FileUtil.copyStream(is, new FileOutputStream(f));
    } catch (final FileNotFoundException e) {
        e.printStackTrace();
    }
    return false;
}

From source file:com.yojiokisoft.globish1500.exception.MyUncaughtExceptionHandler.java

/**
 * ??./*from  www.j av a2  s.c om*/
 *
 * @param file
 * @return
 */
private static String getFileBody(File file) {
    StringBuilder sb = new StringBuilder();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(file));
        String line;
        while ((line = br.readLine()) != null) {
            sb.append(line).append("\r\n");
        }
        br.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        MyFile.closeQuietly(br);
    }
    return sb.toString();
}

From source file:FileUtil.java

/**
 * Gets the content from a File as StringArray List.
 *
 * @param fileName A file to read from./* ww w. j  ava2s .c o m*/
 * @return List of individual line of the specified file. List may be empty but not
 *         null.
 * @throws IOException
 */
public static ArrayList getFileContent(String fileName) throws IOException {
    ArrayList result = new ArrayList();

    File aFile = new File(fileName);

    if (!aFile.isFile()) {
        //throw new IOException( fileName + " is not a regular File" );
        return result; // None
    }

    BufferedReader reader = null;

    try {
        reader = new BufferedReader(new FileReader(aFile));
    } catch (FileNotFoundException e1) {
        // TODO handle Exception
        e1.printStackTrace();

        return result;
    }

    String aLine = null;

    while ((aLine = reader.readLine()) != null) {
        result.add(aLine + "\n");
    }

    reader.close();

    return result;
}

From source file:com.marketplace.Utils.java

/**
 * Converts a list of Android permissions to a corresponding int value in
 * database. If a new permission is found, then that permission gets added
 * to an external file 'permission' found in the directory config.
 * //w w  w .  j  a  v  a2 s .c  om
 * @param permissions
 *            a list of permissions that needs to be converted.
 * 
 * @return a list of corresponding int value.
 */
synchronized public static List<Integer> permissionToInt(List<String> permissions) {
    List<Integer> pListArr = new ArrayList<Integer>(permissions.size());

    for (String permission : permissions) {
        if (pMap.containsKey(permission)) {
            pListArr.add(pMap.get(permission));
        } else {
            try {
                log.info("New permission found. Adding to the database");

                PrintStream printStream = new PrintStream(new FileOutputStream(Utils.fileName, true), true);
                printStream.print(permission + "\t" + (pMap.size() + 1) + "\n");
                printStream.close();

                pMap.put(permission, pMap.size() + 1);
                new Sender().doBasicHttpPost("{\"permission\":\"" + permission + "\"}",
                        Constants.newPermissionUrlJson);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (ConnectivityException e) {
                log.info("There was a problem connecting to the database");
            }
        }
    }

    return pListArr;
}