List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { try {/*w w w . j av a 2s. c o m*/ String s = "Hello world from java2s.com"; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF(s); // set the file pointer at 0 position raf.seek(0); // create an array equal to the length of raf byte[] arr = new byte[10]; // read the file raf.readFully(arr, 3, 7); // create a new string based on arr String s2 = new String(arr); // print it System.out.println(s2); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from www .j a v a 2 s .c o m*/ String s = "tutorial from java2s.com"; Reader reader = new StringReader(s); for (int i = 0; i < 5; i++) { char c = (char) reader.read(); System.out.println(c); } reader.mark(10); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.reset(); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/* w ww . j a va 2s. c om*/ // create a new RandomAccessFile with filename Example RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeUTF("java2s.com Hello World"); // set the file pointer at 0 position raf.seek(0); // read and print the contents of the file System.out.println(raf.readUTF()); // return the file pointer System.out.println(raf.getFilePointer()); // change the position of the file pointer raf.seek(5); // return the file pointer System.out.println(raf.getFilePointer()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// ww w . j av a 2s . c o m double d = 1.2345678; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); raf.writeDouble(123.456789); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readDouble()); // set the file pointer at 0 position raf.seek(0); // write a double at the start raf.writeDouble(d); // set the file pointer at 0 position raf.seek(0); // read double System.out.println(raf.readDouble()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:SocketTest.java
public static void main(String[] args) { try {//from w w w . j av a 2 s . co m Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13); try { InputStream inStream = s.getInputStream(); Scanner in = new Scanner(inStream); while (in.hasNextLine()) { String line = in.nextLine(); System.out.println(line); } } finally { s.close(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Person.java
public static void main(String[] args) { Person p1 = new Person("John", "Male", 1.7); Person p2 = new Person("Wally", "Male", 1.7); Person p3 = new Person("Katrina", "Female", 1.4); File fileObject = new File("person.ser"); try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileObject))) { oos.writeObject(p1);//from w ww .j a v a 2s . c om oos.writeObject(p2); oos.writeObject(p3); // Display the serialized objects on the standard output System.out.println(p1); System.out.println(p2); System.out.println(p3); } catch (IOException e) { e.printStackTrace(); } }
From source file:Test.java
public static void main(String[] args) { try {/*from www .ja v a 2s . c o m*/ Path source = Paths.get("/home"); Path target = Paths.get("/backup"); Files.walkFileTree(source, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new CopyDirectory(source, target)); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) { String host = args[0];//from w ww . ja va 2s .co m int port = Integer.parseInt(args[1]); try { System.out.println("Locating socket factory for SSL..."); SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); System.out.println("Creating secure socket to " + host + ":" + port); SSLSocket socket = (SSLSocket) factory.createSocket(host, port); System.out.println("Enabling all available cipher suites..."); String[] suites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(suites); System.out.println("Registering a handshake listener..."); socket.addHandshakeCompletedListener(new MyHandshakeListener()); System.out.println("Starting handshaking..."); socket.startHandshake(); System.out.println("Just connected to " + socket.getRemoteSocketAddress()); } catch (IOException e) { e.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 www . ja va 2s .c om*/ for (int i = 0; i < 5; i++) { char c = (char) reader.read(); System.out.print(c); } reader.mark(10); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.reset(); for (int i = 0; i < 6; i++) { char c = (char) reader.read(); System.out.println(c); } reader.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/* w w w . ja va2 s .c o m*/ char c = 'J'; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write something in the file raf.writeChar('A'); // set the file pointer at 0 position raf.seek(0); // read char System.out.println(raf.readChar()); // set the file pointer at 0 position raf.seek(0); // write a char at the start raf.writeChar(c); // set the file pointer at 0 position raf.seek(0); System.out.println(raf.readChar()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }