List of usage examples for java.io PrintWriter close
public void close()
From source file:Main.java
public static void main(String[] args) { try {/* w w w .j av a 2 s . c o m*/ PrintWriter pw = new PrintWriter("c:/text.txt"); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/* w w w .j a v a 2s .com*/ PrintWriter pw = new PrintWriter("c:/text.txt", "ACSII"); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.berkeley.compbio.phyloutils.NearestNodeFinder.java
public static void main(String[] argv) throws IOException, NoSuchNodeException { //service.setGreengenesRawFilename(argv[0]); service.setHugenholtzFilename(argv[0]); //service.setSynonymService(NcbiTaxonomyClient.getInstance()); service.init();//from w ww.jav a 2 s. co m final int[] targetIds = IntArrayReader.read(argv[1]); int[] queryIds = IntArrayReader.read(argv[2]); final double minDistance = Double.parseDouble(argv[3]); // implement leave-one-out at any level Map<Integer, Double> results = Parallel.map(new ArrayIterator(queryIds), new Function<Integer, Double>() { public Double apply(Integer queryId) { try { double best = Double.MAX_VALUE; for (int targetId : targetIds) { double d = service.minDistanceBetween(queryId, targetId); if (d >= minDistance) { best = Math.min(best, d); } } return best; } catch (NoSuchNodeException e) { throw new Error(e); } } }); String outfileName = argv[4]; PrintWriter out = new PrintWriter(outfileName); out.println("id\tdist"); for (Map.Entry<Integer, Double> entry : results.entrySet()) { out.println(entry.getKey() + "\t" + entry.getValue()); } out.close(); }
From source file:Main.java
public static void main(String[] args) { try {/*ww w . j a v a 2 s .c o m*/ PrintWriter pw = new PrintWriter(new File("c:/text.txt")); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from www .ja va2 s . c om PrintWriter pw = new PrintWriter(new FileWriter("c:/text.txt")); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/* w w w . j a va 2 s .c o m*/ PrintWriter pw = new PrintWriter(new File("c:/text.txt"), "ACSII"); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:ProductionJS.java
/** * @param args//from w ww. ja v a 2s.com */ public static void main(String[] args) { boolean precondition = true; BackupLog backupLog = new BackupLog("log/backupLog.txt"); Property properties = null; Settings settings = null; // Load main cfg file try { properties = new Property("cfg/cfg"); } catch (IOException e) { backupLog.log("ERROR : Config file not found"); precondition = false; } // Load cfg for Log4J if (precondition) { try { DOMConfigurator.configureAndWatch(properties.getProperty("loggerConfiguration")); logger.info("ProductionJS is launched\n_______________________"); } catch (Exception e) { backupLog.log(e.getMessage()); precondition = false; } } // Load settings for current execution if (precondition) { try { settings = new Settings(new File(properties.getProperty("importConfiguration"))); } catch (IOException e) { logger.error("Properties file not found"); precondition = false; } catch (org.json.simple.parser.ParseException e) { logger.error("Properties file reading error : JSON may be invalid, check it!"); precondition = false; } } // All is OK : GO! if (precondition) { logger.info("Configuration OK"); logger.info("\"_______________________\nConcat BEGIN\n_______________________\n"); Concat concat = new Concat(); try { if (settings.getPrior() != null) { logger.info("Add Prior files\n_______________________\n"); concat.addJSONArray(settings.getPrior()); } for (int i = 0; i < settings.getIn().size(); i++) { ProductionJS.logger.info("Importation number " + (i + 1)); ProductionJS.logger.info("Directory imported " + settings.getIn().get(i)); Directory dir = new Directory(new File(settings.getIn().get(i).toString())); dir.scan(); concat.add(dir.getFiles()); } concat.output(settings.getOut()); logger.info("\"_______________________\nConcat END\n_______________________\n"); if (settings.getMinify() != null && settings.getMinify() == true) { logger.info( "\"_______________________\nMinify of concatened file BEGIN\n_______________________\n"); new Minify(new File(settings.getOut()), settings.getOut()); logger.info( "\"_______________________\nMinify of concatened file END\n_______________________\n"); } if (settings.getLicense() != null) { logger.info("Add License\n_______________________\n"); concat = new Concat(); UUID uniqueID = UUID.randomUUID(); PrintWriter tmp = new PrintWriter(uniqueID.toString() + ".txt"); tmp.println(settings.getLicense()); tmp.close(); File license = new File(uniqueID.toString() + ".txt"); concat.add(license); File out = new File(settings.getOut()); File tmpOut = new File(uniqueID + out.getName()); out.renameTo(tmpOut); concat.add(tmpOut); concat.output(settings.getOut()); license.delete(); tmpOut.delete(); } } catch (IOException e) { StackTrace stackTrace = new StackTrace(e.getStackTrace()); logger.error("An error occurred " + e.getMessage() + " " + stackTrace.toString()); } } }
From source file:Main.java
public static void main(String[] args) { try {// w ww .j av a 2 s .co m PrintWriter pw = new PrintWriter(new FileWriter("c:/text.txt"), true); // append chars pw.append('H'); pw.append('e'); pw.append('l'); pw.append('l'); pw.append('o'); // flush the writer pw.flush(); pw.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.qwazr.utils.HtmlUtils.java
public static void main(String args[]) throws IOException { if (args != null && args.length == 2) { List<String> lines = FileUtils.readLines(new File(args[0])); FileWriter fw = new FileWriter(new File(args[1])); PrintWriter pw = new PrintWriter(fw); for (String line : lines) pw.println(StringEscapeUtils.unescapeHtml4(line)); pw.close(); fw.close();/* ww w. ja v a 2s . co m*/ } String text = "file://­Users/ekeller/Moteur/infotoday_enterprisesearchsourcebook08/Open_on_Windows.exe"; System.out.println(htmlWrap(text, 20)); System.out.println(htmlWrapReduce(text, 20, 80)); String url = "file://Users/ekeller/Moteur/infotoday_enterprisesearchsourcebook08/Open_on_Windows.exe?test=2"; System.out.println(urlHostPathWrapReduce(url, 80)); }
From source file:BufferedSocketClient.java
public static void main(String args[]) throws Exception { Socket socket1;//from w w w . ja va 2 s .c o m int portNumber = 1777; String str = "initialize"; socket1 = new Socket(InetAddress.getLocalHost(), portNumber); BufferedReader br = new BufferedReader(new InputStreamReader(socket1.getInputStream())); PrintWriter pw = new PrintWriter(socket1.getOutputStream(), true); pw.println(str); while ((str = br.readLine()) != null) { System.out.println(str); pw.println("bye"); if (str.equals("bye")) break; } br.close(); pw.close(); socket1.close(); }