List of usage examples for java.io FileNotFoundException printStackTrace
public void printStackTrace(PrintStream s)
From source file:net.schweerelos.parrot.CombinedParrotApp.java
/** * @param args// ww w . j a v a 2s . c om */ @SuppressWarnings("static-access") public static void main(String[] args) { CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("help") .withDescription("Shows usage information and quits the program").create("h")); options.addOption( OptionBuilder.withLongOpt("datafile").withDescription("The file with instances to use (required)") .hasArg().withArgName("file").isRequired().create("f")); options.addOption(OptionBuilder.withLongOpt("properties") .withDescription("Properties file to use. Default: " + System.getProperty("user.home") + File.separator + ".digital-parrot" + File.separator + "parrot.properties") .hasArg().withArgName("prop").create("p")); try { // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("h")) { // this is only executed when all required options are present _and_ the help option is specified! printHelp(options); return; } String datafile = line.getOptionValue("f"); if (!datafile.startsWith("file:") || !datafile.startsWith("http:")) { datafile = "file:" + datafile; } String propertiesPath = System.getProperty("user.home") + File.separator + ".digital-parrot" + File.separator + "parrot.properties"; if (line.hasOption("p")) { propertiesPath = line.getOptionValue("p"); } final Properties properties = new Properties(); File propertiesFile = new File(propertiesPath); if (propertiesFile.exists() && propertiesFile.canRead()) { try { properties.load(new FileReader(propertiesFile)); } catch (FileNotFoundException e) { e.printStackTrace(System.err); System.exit(1); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } } final String url = datafile; // we need a "final" var for the anonymous class SwingUtilities.invokeLater(new Runnable() { public void run() { CombinedParrotApp inst = null; try { inst = new CombinedParrotApp(properties); inst.loadModel(url); } catch (Exception e) { JOptionPane.showMessageDialog(null, "There has been an error while starting the program.\nThe program will exit now.", APP_TITLE + " Error", JOptionPane.ERROR_MESSAGE); e.printStackTrace(System.err); System.exit(1); } if (inst != null) { inst.setLocationRelativeTo(null); inst.setVisible(true); } } }); } catch (ParseException exp) { printHelp(options); } }
From source file:com.iflytek.spider.util.DomUtil.java
/** * Returns parsed dom tree or null if any error * //ww w .j av a 2 s . c om * @param is * @return A parsed DOM tree from the given {@link InputStream}. */ public static Element getDom(InputStream is) { Element element = null; DOMParser parser = new DOMParser(); InputSource input; try { input = new InputSource(is); input.setEncoding("UTF-8"); parser.parse(input); int i = 0; while (!(parser.getDocument().getChildNodes().item(i) instanceof Element)) { i++; } element = (Element) parser.getDocument().getChildNodes().item(i); } catch (FileNotFoundException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } catch (SAXException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } catch (IOException e) { e.printStackTrace(LogUtil.getWarnStream(LOG)); } return element; }