List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:HTMLDemo.java
public static void main(String[] a) throws IOException { PrintWriter pw = new PrintWriter(new FileWriter("test.html")); DecimalFormat ff = new DecimalFormat("#0"), cf = new DecimalFormat("0.0"); pw.println("<TABLE BORDER><TR><TH>Fahrenheit<TH>Celsius</TR>"); for (double f = 100; f <= 400; f += 10) { double c = 5 * (f - 32) / 9; pw.println("<TR ALIGN=RIGHT><TD>" + ff.format(f) + "<TD>" + cf.format(c)); }/*from ww w. j a va 2 s .co m*/ pw.println("</TABLE>"); pw.close(); // Without this, the output file may be empty }
From source file:clientetcp.ClienteTCP.java
public static void main(String[] args) { try {//from w w w. ja v a 2s . com SSLClient client = new SSLClient(); SSLSocket s = (SSLSocket) client.createSocket("localhost", 7443); PrintWriter writer = new PrintWriter(s.getOutputStream()); InputStream reader = s.getInputStream(); writer.println("Hola"); } catch (Exception exception) { } }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww .j a v a2 s . c o m*/ BufferedReader input = new BufferedReader(new FileReader(args[0])); ArrayList list = new ArrayList(); String line; while ((line = input.readLine()) != null) { list.add(line); } input.close(); Collections.reverse(list); PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); for (Iterator i = list.iterator(); i.hasNext();) { output.println((String) i.next()); } output.close(); } catch (IOException e) { System.err.println(e); } }
From source file:Main.java
public static void main(String[] args) throws Exception { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println(stdin.readLine()); BufferedReader in = new BufferedReader(new FileReader("Main.java")); String s, s2 = new String(); while ((s = in.readLine()) != null) s2 += s + "\n"; in.close();/*ww w.j a va 2 s . c om*/ StringReader in1 = new StringReader(s2); int c; while ((c = in1.read()) != -1) System.out.print((char) c); BufferedReader in2 = new BufferedReader(new StringReader(s2)); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out"))); int lineCount = 1; while ((s = in2.readLine()) != null) out1.println(lineCount++ + ": " + s); out1.close(); }
From source file:Random4.java
public static void main(String[] argv) throws IOException { // java.util.Random methods are non-static, do need to construct Math Random r = new Random(); PrintWriter file1 = new PrintWriter(new FileWriter("file1")); PrintWriter file2 = new PrintWriter(new FileWriter("file2")); for (int i = 0; i < 10000; i++) { file1.println(r.nextDouble()); file2.println(r.nextGaussian()); }/*from w ww .j a v a 2 s. c o m*/ file1.close(); file2.close(); }
From source file:NewFingerServer.java
public static void main(String[] arguments) throws Exception { ServerSocketChannel sockChannel = ServerSocketChannel.open(); sockChannel.configureBlocking(false); InetSocketAddress server = new InetSocketAddress("localhost", 79); ServerSocket socket = sockChannel.socket(); socket.bind(server);/*from w w w. j a v a2 s .co m*/ Selector selector = Selector.open(); sockChannel.register(selector, SelectionKey.OP_ACCEPT); while (true) { selector.select(); Set keys = selector.selectedKeys(); Iterator it = keys.iterator(); while (it.hasNext()) { SelectionKey selKey = (SelectionKey) it.next(); it.remove(); if (selKey.isAcceptable()) { ServerSocketChannel selChannel = (ServerSocketChannel) selKey.channel(); ServerSocket selSocket = selChannel.socket(); Socket connection = selSocket.accept(); InputStreamReader isr = new InputStreamReader(connection.getInputStream()); BufferedReader is = new BufferedReader(isr); PrintWriter pw = new PrintWriter(new BufferedOutputStream(connection.getOutputStream()), false); pw.println("NIO Finger Server"); pw.flush(); String outLine = null; String inLine = is.readLine(); if (inLine.length() > 0) { outLine = inLine; } readPlan(outLine, pw); pw.flush(); pw.close(); is.close(); connection.close(); } } } }
From source file:com.leonarduk.finance.chart.PieChartFactory.java
/** * Starting point for the demo.//from w w w . ja v a 2 s . co m * * @param args * ignored. */ public static void main(final String[] args) { final PieChartFactory factory = new PieChartFactory("Title"); factory.put("A", 12.2).put("B", 13.2).put("C", 31.2); try { // write an HTML page incorporating the image with an image map final File file2 = new File("multipiechart100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println(ChartDisplay.saveImageAsPngAndReturnHtmlLink("345", 400, 400, factory.buildChart())); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (final IOException e) { System.out.println(e.toString()); } }
From source file:org.jfree.chart.demo.ImageMapDemo7.java
/** * Starting point for the demo.//w w w . j ava2 s.c o m * * @param args ignored. */ public static void main(final String[] args) { final XYDataset data = new SampleXYDataset2(); final JFreeChart chart = ChartFactory.createScatterPlot("Scatter Plot Demo", "X", "Y", data, PlotOrientation.VERTICAL, true, true, false); // final Legend legend = chart.getLegend(); // if (legend instanceof StandardLegend) { // final StandardLegend sl = (StandardLegend) legend; // sl.setDisplaySeriesShapes(true); //} final NumberAxis domainAxis = (NumberAxis) chart.getXYPlot().getDomainAxis(); domainAxis.setAutoRangeIncludesZero(false); chart.setBackgroundPaint(java.awt.Color.white); // **************************************************************************** // * JFREECHART DEVELOPER GUIDE * // * The JFreeChart Developer Guide, written by David Gilbert, is available * // * to purchase from Object Refinery Limited: * // * * // * http://www.object-refinery.com/jfreechart/guide.html * // * * // * Sales are used to provide funding for the JFreeChart project - please * // * support us so that we can continue developing free software. * // **************************************************************************** // save it to an image try { final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); final File file1 = new File("scatter100.png"); ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info); // write an HTML page incorporating the image with an image map final File file2 = new File("scatter100.html"); final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2)); final PrintWriter writer = new PrintWriter(out); writer.println("<HTML>"); writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>"); writer.println("<BODY>"); // ChartUtilities.writeImageMap(writer, "chart", info); writer.println("<IMG SRC=\"scatter100.png\" " + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">"); writer.println("</BODY>"); writer.println("</HTML>"); writer.close(); } catch (IOException e) { System.out.println(e.toString()); } }
From source file:MainClass.java
License:asdf
public static void main(String[] args) throws IOException { try {// w w w .j a v a 2 s. co m BufferedReader in4 = new BufferedReader(new StringReader("asdf")); PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out"))); int lineCount = 1; String s = null; while ((s = in4.readLine()) != null) out1.println(lineCount++ + ": " + s); out1.close(); } catch (EOFException e) { System.err.println("End of stream"); } }
From source file:eval.dataset.ParseWikiLog.java
public static void main(String[] ss) throws FileNotFoundException, ParserConfigurationException, IOException { FileInputStream fin = new FileInputStream("data/enwiki-20151201-pages-logging.xml.gz"); GzipCompressorInputStream gzIn = new GzipCompressorInputStream(fin); InputStreamReader reader = new InputStreamReader(gzIn); BufferedReader br = new BufferedReader(reader); PrintWriter pw = new PrintWriter(new FileWriter("data/user_page.txt")); pw.println( "#list of user names and pages that they have edited, deleted or created. These info are mined from logitems of enwiki-20150304-pages-logging.xml.gz"); TreeMap<String, Set<String>> userPageList = new TreeMap(); TreeSet<String> pageList = new TreeSet(); int counterEntry = 0; String currentUser = null;//from ww w.j a v a 2 s . c o m String currentPage = null; try { for (String line = br.readLine(); line != null; line = br.readLine()) { if (line.trim().equals("</logitem>")) { counterEntry++; if (currentUser != null && currentPage != null) { updateMap(userPageList, currentUser, currentPage); pw.println(currentUser + "\t" + currentPage); pageList.add(currentPage); } currentUser = null; currentPage = null; } else if (line.trim().startsWith("<username>")) { currentUser = line.trim().split(">")[1].split("<")[0].replace(" ", "_"); } else if (line.trim().startsWith("<logtitle>")) { String content = line.trim().split(">")[1].split("<")[0]; if (content.split(":").length == 1) { currentPage = content.replace(" ", "_"); } } } } catch (IOException ex) { Logger.getLogger(ParseWikiLog.class.getName()).log(Level.SEVERE, null, ex); } pw.println("#analysed " + counterEntry + " entries of wikipesia log file"); pw.println("#gathered a list of unique user of size " + userPageList.size()); pw.println("#gathered a list of pages of size " + pageList.size()); pw.close(); gzIn.close(); PrintWriter pwUser = new PrintWriter(new FileWriter("data/user_list_page_edited.txt")); pwUser.println( "#list of unique users and pages that they have edited, extracted from logitems of enwiki-20150304-pages-logging.xml.gz"); for (String user : userPageList.keySet()) { pwUser.print(user); Set<String> getList = userPageList.get(user); for (String page : getList) { pwUser.print("\t" + page); } pwUser.println(); } pwUser.close(); PrintWriter pwPage = new PrintWriter(new FileWriter("data/all_pages.txt")); pwPage.println("#list of the unique pages that are extracted from enwiki-20150304-pages-logging.xml.gz"); for (String page : pageList) { pwPage.println(page); } pwPage.close(); System.out.println("#analysed " + counterEntry + " entries of wikipesia log file"); System.out.println("#gathered a list of unique user of size " + userPageList.size()); System.out.println("#gathered a list of pages of size " + pageList.size()); }