List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { CharSequence csq = "from java2s.com!"; Writer writer = new PrintWriter(System.out); try {//from w ww . j a va2 s.c o m // append a sequence and change line writer.append("This is an example\n"); // flush the writer writer.flush(); // append a new sequence writer.append(csq); // 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) { char[] c = { 'h', 'e', 'l', 'l', 'o' }; PipedWriter writer = new PipedWriter(); PipedReader reader = new PipedReader(); try {/* w ww .j a va 2s.c o m*/ // connect the reader and the writer writer.connect(reader); writer.write(c, 0, 3); // print what we wrote for (int i = 0; i < 3; i++) { System.out.println((char) reader.read()); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String str = "tutorial from java2s.com!"; Writer writer = new PrintWriter(System.out); try {//from w w w . ja va 2 s.c o m // write a string writer.write(str); // flush the writer writer.flush(); // change line and write another string writer.write("\nThis is an example"); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com"; StringReader sr = new StringReader(s); // create a new PushBack reader based on our string reader PushbackReader pr = new PushbackReader(sr, 20); try {/*from w ww . j av a 2 s . com*/ // read the first five chars for (int i = 0; i < 5; i++) { char c = (char) pr.read(); System.out.println(c); } pr.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String str = "tutorial from java2s.com!"; Writer writer = new PrintWriter(System.out); try {/*from www. j a va 2 s .c o m*/ // write a string portion writer.write(str, 0, 5); // flush the writer writer.flush(); // write another string portion writer.write(str, 5, 6); // flush the stream again writer.flush(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:"); try {/*from w w w .ja v a 2 s . co m*/ FileStore fs = Files.getFileStore(path); printDetails(fs, AclFileAttributeView.class); printDetails(fs, BasicFileAttributeView.class); printDetails(fs, DosFileAttributeView.class); printDetails(fs, FileOwnerAttributeView.class); printDetails(fs, PosixFileAttributeView.class); printDetails(fs, UserDefinedFileAttributeView.class); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Path path = Paths.get("C:\\Java_Dev\\test1.txt"); try {/*from w w w. ja va2 s. c o m*/ BasicFileAttributeView bfv = Files.getFileAttributeView(path, BasicFileAttributeView.class); BasicFileAttributes bfa = bfv.readAttributes(); System.out.format("Size:%s bytes %n", bfa.size()); System.out.format("Creation Time:%s %n", bfa.creationTime()); System.out.format("Last Access Time:%s %n", bfa.lastAccessTime()); FileTime newLastModifiedTime = null; FileTime newLastAccessTime = null; FileTime newCreateTime = FileTime.from(Instant.now()); bfv.setTimes(newLastModifiedTime, newLastAccessTime, newCreateTime); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "tutorial from java2s.com"; CharBuffer cb = CharBuffer.allocate(100); Reader reader = new StringReader(s); try {/*from www . ja v a2 s. c o m*/ reader.read(cb); cb.flip(); // print the char buffer System.out.println(cb.toString()); reader.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {/*from w ww. j a v a 2 s. c o m*/ String s = "from java2s.com"; StringReader sr = new StringReader(s); // create a new PushBack reader based on our string reader PushbackReader pr = new PushbackReader(sr, 20); // read the first five chars for (int i = 0; i < 5; i++) { char c = (char) pr.read(); System.out.println(c); } // try to reset pr.reset(); pr.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { PipedWriter writer = new PipedWriter(); PipedReader reader = new PipedReader(); try {//ww w . j a v a 2s . co m // connect the reader and the writer reader.connect(writer); writer.write(70); writer.write(71); // check if reader is ready to read System.out.println(reader.ready()); // print the char array for (int i = 0; i < 2; i++) { System.out.println("" + (char) reader.read()); } } catch (IOException ex) { ex.printStackTrace(); } }