List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] a) { try {//from w ww . j av a 2 s . c om URI uri = new URI("http://www.java2s.com"); Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); } if (desktop != null) desktop.browse(uri); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { try {// ww w. j a v a 2s . com String data = "data in UDP"; byte[] buffer = data.getBytes(); DatagramPacket packet = new DatagramPacket(buffer, buffer.length, new InetSocketAddress("localhost", 5002)); DatagramSocket socket = new DatagramSocket(5003); System.out.println("Sending a packet..."); socket.send(packet); } catch (IOException e) { e.printStackTrace(); } }
From source file:SystemInfo.java
public static void main(String args[]) { try {//from w w w . java 2s . c o m Properties sysprops = System.getProperties(); sysprops.store(System.out, "System Properties"); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char c = 'A'; Writer writer = new PrintWriter(System.out); try {// w ww . j a va 2s.com // append a char writer.append('c'); // append a new char writer.append(c); // flush the writer to see the result writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { String str = "This is a test, 200.89 which is simple 50"; StringReader sr = new StringReader(str); StreamTokenizer st = new StreamTokenizer(sr); try {/*from w ww .j a va 2 s.com*/ while (st.nextToken() != StreamTokenizer.TT_EOF) { switch (st.ttype) { case StreamTokenizer.TT_WORD: /* a word has been read */ System.out.println("String value: " + st.sval); break; case StreamTokenizer.TT_NUMBER: /* a number has been read */ System.out.println("Number value: " + st.nval); break; } } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {//from www . java 2 s .co m byte[] buffer = new byte[1024]; DatagramPacket packet = new DatagramPacket(buffer, buffer.length); DatagramSocket socket = new DatagramSocket(5002); System.out.println("Waiting for a packet..."); socket.receive(packet); System.out.println("Just received packet from " + packet.getSocketAddress()); buffer = packet.getData(); System.out.println(new String(buffer)); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { // Assume that C:\Java_Dev\test1.txt file exists Path p1 = Paths.get("C:\\Java_Dev\\test1.txt"); Path p2 = Paths.get("C:\\Java_Dev\\..\\Java_Dev\\test1.txt"); // Assume that C:\abc.txt file does not exist Path p3 = Paths.get("C:\\abc.txt"); Path p4 = Paths.get("C:\\abc.txt"); try {/*from w w w.j a v a2s. co m*/ boolean isSame = Files.isSameFile(p1, p2); System.out.println("p1 and p2 are the same: " + isSame); isSame = Files.isSameFile(p3, p4); System.out.println("p3 and p4 are the same: " + isSame); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] a) { try {/*ww w. j a va2 s. c o m*/ URI uri = new URI("http://www.java2s.com"); Desktop desktop = null; if (Desktop.isDesktopSupported()) { desktop = Desktop.getDesktop(); desktop.isSupported(Desktop.Action.PRINT); } if (desktop != null) desktop.browse(uri); } catch (IOException ioe) { ioe.printStackTrace(); } catch (URISyntaxException use) { use.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; Reader reader = new StringReader(s); try {/*from w ww. j av a 2 s. c o m*/ // read the first five chars for (int i = 0; i < 5; i++) { char c = (char) reader.read(); // skip a char every time reader.skip(1); System.out.println(c); } reader.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s.c om*/ RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeUTF("java2s.com"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }