List of usage examples for java.lang Exception printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//from w ww . j a v a 2 s.c om OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from ww w . j a v a 2s . c om*/ OutputStream os = new FileOutputStream("test.txt"); InputStream is = new FileInputStream("test.txt"); // write something os.write('A'); // flush the stream os.flush(); // close the stream but it does nothing os.close(); // read what we wrote System.out.println((char) is.read()); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:ImagePatternShapePDF.java
public static void main(String[] args) { Document document = new Document(); try {//from ww w . j av a2 s. com PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("ImagePatternShapePDF.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfPatternPainter p = cb.createPattern(30f, 30f, 30f, 30f); Image img = Image.getInstance("logo.png"); p.addImage(img, img.scaledWidth(), 0f, 0f, img.scaledHeight(), 0f, 0f); p.setPatternMatrix(1f, 0f, 0f, 1f, 60f, 60f); cb.setPatternFill(p); cb.circle(150f, 400f, 150f); cb.fillStroke(); } catch (Exception e) { e.printStackTrace(); } document.close(); }
From source file:Main.java
public static void main(String[] args) { byte[] b = { 'h', 'e', 'l', 'l', 'o' }; try {//from w w w . j a va 2 s . co m // create a new output stream OutputStream os = new FileOutputStream("test.txt"); // craete a new input stream InputStream is = new FileInputStream("test.txt"); // write something os.write(b); // read what we wrote for (int i = 0; i < b.length; i++) { System.out.print((char) is.read()); } os.close(); is.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {// w ww.j a v 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); dp.setData(buffer); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String args[]) { try {/*w w w. j ava 2 s . 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); dp.setSocketAddress(InetSocketAddress.createUnresolved("google.com", 8080)); } } catch (Exception e) { e.printStackTrace(); } }
From source file:SOAPResponse.java
public static void main(String[] args) { try {/*from w ww . ja v a2s .com*/ SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance(); SOAPConnection connection = sfc.createConnection(); MessageFactory mf = MessageFactory.newInstance(); SOAPMessage sm = mf.createMessage(); QName bodyName = new QName("http://YourSOAPServer.com", "GetQuote", "d"); URL endpoint = new URL("http://YourSOAPServer.com"); SOAPMessage response = connection.call(sm, endpoint); SOAPBody sb = response.getSOAPBody(); java.util.Iterator iterator = sb.getChildElements(bodyName); while (iterator.hasNext()) { SOAPBodyElement bodyElement = (SOAPBodyElement) iterator.next(); String val = bodyElement.getValue(); System.out.println("The Value is:" + val); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:CellAlignmentBaselinePDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {/* www . java 2 s . c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellAlignmentBaselinePDF.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; table.getDefaultCell().setVerticalAlignment(Element.ALIGN_BASELINE); Paragraph p = new Paragraph( "Text Text\nText Text Text\nText\nText\nText\nText\nText\nText\nText Text Text\nText Text\nText "); table.addCell("default alignment"); cell = new PdfPCell(p); table.addCell(cell); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:CellAlignmentCenterPDF.java
public static void main(String[] args) { Document document = new Document(PageSize.A4.rotate(), 10, 10, 10, 10); try {/*ww w. j ava2 s . com*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("CellAlignmentCenterPDF.pdf")); document.open(); PdfPTable table = new PdfPTable(2); PdfPCell cell; Paragraph p = new Paragraph( "Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text "); table.addCell("default alignment"); cell = new PdfPCell(p); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell("right alignment"); document.add(table); } catch (Exception de) { de.printStackTrace(); } document.close(); }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {/* ww w . j a va2s . c o m*/ OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }