List of usage examples for java.lang Exception printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { try {/*from w ww. jav a2 s. c o m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); // create a new FileInputStream to read what we write FileInputStream in = new FileInputStream("test.txt"); // write something in the file writer.write(70); // flush the stream writer.flush(); // read what we write System.out.println((char) in.read()); // close the stream writer.close(); os.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com "; try {/* w w w . j av a2 s .c om*/ PrintWriter pw = new PrintWriter(System.out); // append the sequence pw.append(s); // flush the writer pw.flush(); // print another string pw.println("This is an example"); // flush the writer again pw.flush(); // close the writer 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 2s. c o m int port = 80; DatagramSocket ds = new DatagramSocket(port); byte buffer[] = new byte[BUFSIZE]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); // Receive data ds.receive(dp); // Display address from the datagram packet InetAddress ia = dp.getAddress(); System.out.println(ia); // Display port from the datagram packet System.out.println(dp.getPort()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/*from w w w . jav a 2s . com*/ int port = 80; DatagramSocket ds = new DatagramSocket(port); byte buffer[] = new byte[BUFSIZE]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); // Receive data ds.receive(dp); // Display address from the datagram packet InetAddress ia = dp.getAddress(); System.out.println(ia); System.out.println(dp.getSocketAddress()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:SimpleAnnotationsLocalDestinationPDF.java
public static void main(String[] args) { Document document1 = new Document(PageSize.A4, 10, 10, 10, 10); try {//from w ww .j a v a 2 s . co m PdfWriter writer1 = PdfWriter.getInstance(document1, new FileOutputStream("SimpleAnnotationsLocalDestinationPDF.pdf")); writer1.setPdfVersion(PdfWriter.VERSION_1_5); document1.open(); Annotation a = new Annotation("SimpleAnnotationsLocalDestination.pdf", "mark"); document1.add(a); document1.newPage(); document1.newPage(); document1.add(new Chunk("marked chunk").setLocalDestination("mark")); } catch (Exception de) { de.printStackTrace(); } document1.close(); }
From source file:Main.java
public static void main(String args[]) { try {/*from ww w . j a v a 2 s .c om*/ int port = 80; DatagramSocket ds = new DatagramSocket(port); byte buffer[] = new byte[BUFSIZE]; while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); // Receive data ds.receive(dp); // Display address from the datagram packet InetAddress ia = dp.getAddress(); System.out.println(ia); System.out.println(dp.getOffset()); } } catch (Exception e) { e.printStackTrace(); } }
From source file:CellWidthsPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4, 36, 36, 36, 36); try {//from ww w.ja v a 2s.c o m PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellWidthsPDF.pdf")); document.open(); float[] widths = { 0.1f, 0.1f, 0.05f, 0.75f }; PdfPTable table = new PdfPTable(widths); table.addCell("10%"); table.addCell("10%"); table.addCell("5%"); table.addCell("75%"); table.addCell("111111111111111111111111111"); table.addCell("111111111111111"); table.addCell("11111"); table.addCell("11"); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:Main.java
public static void main(String[] args) { byte[] arrByte = new byte[1024]; byte[] byteArray = new byte[] { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; InputStream is = new ByteArrayInputStream(byteArray); PushbackInputStream pis = new PushbackInputStream(is, 10); try {//from w w w .j av a 2s. c o m // read from the buffer one character at a time for (int i = 0; i < byteArray.length; i++) { // read a char into our array arrByte[i] = (byte) pis.read(); System.out.println((char) arrByte[i]); } // unread a char pis.unread('F'); // read again from the buffer arrByte[1] = (byte) pis.read(); System.out.println((char) arrByte[1]); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:GetMethod.java
public static void main(String[] args) { Method[] ms = String.class.getMethods(); for (int i = 0; i < ms.length; i++) { // System.out.println(ms[i].getName()); }//from w w w .j a v a 2 s .c o m Method[] ims = XMLReader.class.getMethods(); for (int i = 0; i < ims.length; i++) { // System.out.println(ims[i].getName()); } Method[] sms = Size.class.getMethods(); for (int i = 0; i < sms.length; i++) { // System.out.println(sms[i].getName()); } String pc = new String(); try { Method setCpu = String.class.getMethod("toString", String.class); setCpu.invoke(pc, "Intel 3.0"); System.out.println(pc.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ebay.recommendations.ItemRecommendations.java
/** * @param args/*w ww .java 2 s. c om*/ */ public static void main(String[] args) { HttpClient client = new HttpClient(); String fullUri = "https://svcs.ebay.com/services/selling/listingrecommendation/v1/item/300878655630/itemRecommendations/"; HttpMethod method = new GetMethod(fullUri); // REPLACE YOUR TOKEN IN THE <YOUR_TOKEN_HERE> PLACE HOLDER method.addRequestHeader("Authorization", "TOKEN <YOUR_TOKEN_HERE>"); method.addRequestHeader("X-EBAY-GLOBAL-ID", "EBAY-US"); method.addRequestHeader("Accept", "application/xml"); try { client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } }