List of usage examples for java.io PrintWriter println
public void println(Object x)
From source file:Main.java
License:asdf
public static void main(String[] arges) throws Exception { InetAddress addr = InetAddress.getByName(null); Socket sk = new Socket(addr, 8888); BufferedReader in = new BufferedReader(new InputStreamReader(sk.getInputStream())); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(sk.getOutputStream())), true); out.println("asdf"); System.out.println(in.readLine()); }
From source file:com.endava.webfundamentals.Main.java
public static void main(String[] args) throws JsonParseException, JsonMappingException, IOException { HttpClient httpClient = HttpClientBuilder.create().build(); HttpGet httpRequest = new HttpGet("http://petstore.swagger.wordnik.com/api/api-docs"); HttpResponse httpResponse = httpClient.execute(httpRequest); ObjectMapper objectMapper = new ObjectMapper(); PetStore petStore = objectMapper.readValue(httpResponse.getEntity().getContent(), PetStore.class); PrintWriter out = new PrintWriter("PetStore.html"); out.println("<html>"); out.println("<header>"); out.println(petStore.getInfo().getTitle()); out.println("</header>"); out.println("<body>"); out.println("Api Version " + petStore.getApiVersion()); out.println("Swagger Version " + petStore.getSwaggerVersion()); out.println("<p>"); out.println(petStore.getInfo().getDescription()); out.println("</p>"); out.println("<p>"); out.println(petStore.getInfo().getContact()); out.println("</p>"); out.println(petStore.getInfo().getLicense()); out.println(petStore.getInfo().getLicenseUrl()); out.println("<p>"); out.println(petStore.getInfo().getTermsOfServiceUrl()); out.println("</p>"); out.println("</body>"); out.println("</html>"); out.close();/*from ww w .ja v a2 s . c o m*/ }
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 w w.ja v a 2 s.c om 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:MainClass.java
public static void main(String args[]) { try {//from w ww . j a v a 2s . c o m PrintWriter pw = new PrintWriter(System.out); // Experiment with some methods pw.println(true); pw.println('A'); pw.println(500); pw.println(40000L); pw.println(45.67f); pw.println(45.67); pw.println("Hello"); pw.println(new Integer("99")); // Close print writer pw.close(); } catch (Exception e) { System.out.println("Exception: " + e); } }
From source file:LogTest.java
public static void main(String[] args) throws IOException { String inputfile = args[0];//from w w w .ja v a 2s . c om String outputfile = args[1]; Map<String, Integer> map = new TreeMap<String, Integer>(); Scanner scanner = new Scanner(new File(inputfile)); while (scanner.hasNext()) { String word = scanner.next(); Integer count = map.get(word); count = (count == null ? 1 : count + 1); map.put(word, count); } scanner.close(); List<String> keys = new ArrayList<String>(map.keySet()); Collections.sort(keys); PrintWriter out = new PrintWriter(new FileWriter(outputfile)); for (String key : keys) out.println(key + " : " + map.get(key)); out.close(); }
From source file:POP3Demo.java
public static void main(String[] args) throws Exception { int POP3Port = 110; Socket client = new Socket("127.0.0.1", POP3Port); InputStream is = client.getInputStream(); BufferedReader sockin = new BufferedReader(new InputStreamReader(is)); OutputStream os = client.getOutputStream(); PrintWriter sockout = new PrintWriter(os, true); String cmd = "user Smith"; sockout.println(cmd); String reply = sockin.readLine(); cmd = "pass "; sockout.println(cmd + "popPassword"); reply = sockin.readLine();//from w w w .ja va 2 s.c o m cmd = "stat"; sockout.println(cmd); reply = sockin.readLine(); if (reply == null) return; cmd = "retr 1"; sockout.println(cmd); if (cmd.toLowerCase().startsWith("retr") && reply.charAt(0) == '+') do { reply = sockin.readLine(); System.out.println("S:" + reply); if (reply != null && reply.length() > 0) if (reply.charAt(0) == '.') break; } while (true); cmd = "quit"; sockout.println(cmd); client.close(); }
From source file:Reverse.java
public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Reverse " + "string_to_reverse"); System.exit(1);/* w w w. j ava 2s .co m*/ } String stringToReverse = URLEncoder.encode(args[0]); URL url = new URL("http://java.sun.com/cgi-bin/backwards"); URLConnection connection = url.openConnection(); connection.setDoOutput(true); PrintWriter out = new PrintWriter(connection.getOutputStream()); out.println("string=" + stringToReverse); out.close(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); in.close(); }
From source file:CompileSourceInMemory.java
public static void main(String args[]) throws IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StringWriter writer = new StringWriter(); PrintWriter out = new PrintWriter(writer); out.println("public class HelloWorld {"); out.println(" public static void main(String args[]) {"); out.println(" System.out.println(\"This is in another java file\");"); out.println(" }"); out.println("}"); out.close();/* w w w. j a v a2 s . com*/ JavaFileObject file = new JavaSourceFromString("HelloWorld", writer.toString()); Iterable<? extends JavaFileObject> compilationUnits = Arrays.asList(file); CompilationTask task = compiler.getTask(null, null, diagnostics, null, null, compilationUnits); boolean success = task.call(); for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { System.out.println(diagnostic.getCode()); System.out.println(diagnostic.getKind()); System.out.println(diagnostic.getPosition()); System.out.println(diagnostic.getStartPosition()); System.out.println(diagnostic.getEndPosition()); System.out.println(diagnostic.getSource()); System.out.println(diagnostic.getMessage(null)); } System.out.println("Success: " + success); if (success) { try { Class.forName("HelloWorld").getDeclaredMethod("main", new Class[] { String[].class }).invoke(null, new Object[] { null }); } catch (ClassNotFoundException e) { System.err.println("Class not found: " + e); } catch (NoSuchMethodException e) { System.err.println("No such method: " + e); } catch (IllegalAccessException e) { System.err.println("Illegal access: " + e); } catch (InvocationTargetException e) { System.err.println("Invocation target: " + e); } } }
From source file:BufferedSocketClient.java
public static void main(String args[]) throws Exception { Socket socket1;/*from w w w .ja va 2 s . c om*/ 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(); }
From source file:EchoServer.java
public static void main(String[] args) { try {//from ww w. ja va 2 s .com // establish server socket ServerSocket s = new ServerSocket(8189); // wait for client connection Socket incoming = s.accept(); try { InputStream inStream = incoming.getInputStream(); OutputStream outStream = incoming.getOutputStream(); Scanner in = new Scanner(inStream); PrintWriter out = new PrintWriter(outStream, true /* autoFlush */); out.println("Hello! Enter BYE to exit."); // echo client input boolean done = false; while (!done && in.hasNextLine()) { String line = in.nextLine(); out.println("Echo: " + line); if (line.trim().equals("BYE")) done = true; } } finally { incoming.close(); } } catch (IOException e) { e.printStackTrace(); } }