public void setImage (String file) { try { image = ImageIO.read( new File(file) ); } catch (IOException e) { e.printStackTrace(); } }
private static String[] getContents(File file) { List<String> content = new ArrayList<>(); try (BufferedReader input = new BufferedReader(new FileReader(file))) { String line = null; // not declared within while loop while ((line = input.readLine()) != null) { content.add(line); } } catch (IOException ex) { ex.printStackTrace(); } return content.toArray(new String[] {}); }
@Override public void run () { BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; try { while ((line = reader.readLine()) != null) { // augment output with java file line references :D printFileLineNumber(line); } } catch (IOException e) { e.printStackTrace(); } }
private static void resolveDummyTags(File treeFile, TwoDimensionalCounter<String, String> pretermLabel, TwoDimensionalCounter<String, String> unigramTagger) { try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), "UTF-8")); TreeReaderFactory trf = new FrenchTreeReaderFactory(); TreeReader tr = trf.newTreeReader(br); PrintWriter pw = new PrintWriter(new PrintStream(new FileOutputStream(new File(treeFile + ".fixed")),false,"UTF-8")); int nTrees = 0; for(Tree t; (t = tr.readTree()) != null;nTrees++) { traverseAndFix(t, pretermLabel, unigramTagger); pw.println(t.toString()); } pw.close(); tr.close(); System.out.println("Processed " +nTrees+ " trees"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private InputStream initPerformanceTest() { try { final File file = new File(writePerformanceTestPath); if (file.exists()) { file.delete(); } file.createNewFile(); return getResources().getAssets().open("performance_test_data"); } catch (IOException e) { e.printStackTrace(); } return null; }
private static void saveIndex() { assert remote2local != null; File downloadDir = new File(System.getProperty("mary.downloadDir", ".")); File licenseIndexFile = new File(downloadDir, "license-index.txt"); try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(licenseIndexFile), "UTF-8"))) { for (URL remote : remote2local.keySet()) { pw.println(remote2local.get(remote) + "|" + remote.toString()); } } catch (IOException e) { System.err.println("Problem updating the index file " + licenseIndexFile.getAbsolutePath()); e.printStackTrace(); } }
File dir = new File(outputPath); if (!dir.exists()) { dir.mkdirs(); JarEntry je = e.nextElement(); String outFileName = outputPath + je.getName(); File f = new File(outFileName); if (je.isDirectory()) { if (!f.exists()) { f.mkdirs(); if (!pf.exists()) { pf.mkdirs(); System.out.println("解压" + fileName + "出错!" + e.getMessage()); } finally { if (jf != null) { jf.close(); } catch (IOException e) { e.printStackTrace();
private static Versioned<Properties> doMetaGetVersionsForNode_ExitOnError(AdminClient adminClient, Integer nodeId) { try { return doMetaGetVersionsForNode(adminClient, nodeId); } catch(IOException e) { System.err.println("Error while retrieving Metadata versions from node : " + nodeId + ". Exception = " + e.getMessage() + " \n"); e.printStackTrace(); System.exit(-1); return null; } }
private static void printLog( String description, File file, PrintStream out ) { if ( file != null && file.exists() ) { out.println( String.format( "---------- BEGIN %s ----------", description ) ); try ( BufferedReader reader = new BufferedReader( new FileReader( file ) ) ) { reader.lines().forEach( out::println ); } catch ( IOException ex ) { out.println( "Unable to collect log files: " + ex.getMessage() ); ex.printStackTrace( out ); } finally { out.println( String.format( "---------- END %s ----------", description ) ); } } }
public boolean hasNext() { try { content = reader.readLine(); if (content == null) { reader.close(); return false; } } catch (IOException e) { e.printStackTrace(); return false; } return true; }
private void setNext() { String line = null; try { line = in.readLine(); } catch (IOException ioe) { ioe.printStackTrace(); } if (line != null) { nextToken = op.apply(line); } else { nextToken = null; } }
@Override public void run () { BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); String line = null; try { while ((line = reader.readLine()) != null) { // augment output with java file line references :D printFileLineNumber(line); } } catch (IOException e) { e.printStackTrace(); } }
/** * @param args */ public static void main(String[] args) { if(args.length != 1) { System.err.printf("Usage: java %s tree_file > trees%n", HebrewTreeReaderFactory.class.getName()); System.exit(-1); } TreebankLanguagePack tlp = new HebrewTreebankLanguagePack(); File treeFile = new File(args[0]); try { TreeReaderFactory trf = new HebrewTreeReaderFactory(); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(treeFile), tlp.getEncoding())); TreeReader tr = trf.newTreeReader(br); int numTrees = 0; for(Tree t; ((t = tr.readTree()) != null); numTrees++) System.out.println(t.toString()); tr.close(); System.err.printf("Processed %d trees.%n",numTrees); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
/** 根据系统时间、前缀、后缀产生一个文件 */ private File createFile(File folder, String prefix, String suffix) { if (!folder.exists() || !folder.isDirectory()) folder.mkdirs(); try { File nomedia = new File(folder, ".nomedia"); //在当前文件夹底下创建一个 .nomedia 文件 if (!nomedia.exists()) nomedia.createNewFile(); } catch (IOException e) { e.printStackTrace(); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.CHINA); String filename = prefix + dateFormat.format(new Date(System.currentTimeMillis())) + suffix; return new File(folder, filename); }
private static void saveIndex() { assert remote2local != null; File downloadDir = new File(System.getProperty("mary.downloadDir", ".")); File licenseIndexFile = new File(downloadDir, "license-index.txt"); try (PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream(licenseIndexFile), "UTF-8"))) { for (URL remote : remote2local.keySet()) { pw.println(remote2local.get(remote) + "|" + remote.toString()); } } catch (IOException e) { System.err.println("Problem updating the index file " + licenseIndexFile.getAbsolutePath()); e.printStackTrace(); } }
URL resource = NativeLibraryLoader.class.getResource(path); if (resource == null) { System.err.println("Not available in classpath: " + path); } else { File file = new File(filename); try { URLConnection urlConnection = resource.openConnection(); int length = urlConnection.getContentLength(); long lastModified = urlConnection.getLastModified(); if (!file.exists() || file.length() != length || file.lastModified() != lastModified) { InputStream in = new BufferedInputStream(urlConnection.getInputStream()); try { e.printStackTrace();
public void setImage (String file) { try { image = ImageIO.read( new File(file) ); } catch (IOException e) { e.printStackTrace(); } }
public void run() { try { internalRun(); } catch(IOException e) { System.out.println("Store processing interrupted " + store + " because of IOException " + e.getMessage()); e.printStackTrace(); } }
protected static String readFile(String path, String fileName) { StringBuilder builder = new StringBuilder(); try ( BufferedReader reader = new BufferedReader(new FileReader(filePath(path, fileName))) ) { String line; while ((line = reader.readLine()) != null) builder.append(line).append(" "); } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
@Override public void nextTuple() { try { String line = null; while ((line = br.readLine()) != null) { collector.emit(Arrays.asList(line.split(","))); } } catch (IOException e) { closeReader(); e.printStackTrace(); } }