List of usage examples for java.io IOException printStackTrace
public void printStackTrace()
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com"; StringReader sr = new StringReader(s); PushbackReader pr = new PushbackReader(sr, 20); try {//from w w w. j ava2 s .co m for (int i = 0; i < 5; i++) { char c = (char) pr.read(); System.out.println(c); } System.out.println("" + pr.markSupported()); pr.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 o m*/ byte[] b = { 1, 2, 3, 4, 5, 6 }; RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); // write 2 bytes in the file raf.write(b, 2, 2); // set the file pointer at 0 position raf.seek(0); // print the two bytes we wrote System.out.println(raf.readByte()); System.out.println(raf.readByte()); raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { File file = new File(args[0]); if (!file.exists()) { System.out.println(args[0] + " does not exist."); return;/*from ww w. ja v a 2s.c o m*/ } if (!(file.isFile() && file.canRead())) { System.out.println(file.getName() + " cannot be read from."); return; } try { FileInputStream fis = new FileInputStream(file); char current; while (fis.available() > 0) { current = (char) fis.read(); System.out.print(current); } } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com"; StringReader sr = new StringReader(s); PushbackReader pr = new PushbackReader(sr, 20); char cbuf[] = new char[5]; try {// w w w . ja v a2s. co m System.out.println(pr.read(cbuf)); System.out.println(cbuf); pr.close(); } 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 ww w.ja va2 s.co m*/ // 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) { PipedWriter writer = new PipedWriter(); PipedReader reader = new PipedReader(); try {//from ww w. ja v a 2s .c o m // connect the reader and the writer reader.connect(writer); writer.write(70); writer.write(71); // read what we wrote for (int i = 0; i < 2; i++) { System.out.println((char) reader.read()); } } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Path startDir = Paths.get(""); FileVisitor<Path> visitor = getFileVisitor(); try {/*from w w w .ja va 2s . c o m*/ Files.walkFileTree(startDir, visitor); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { try {// ww w . j a v a2 s. c o m RandomAccessFile raf = new RandomAccessFile("c:/test.txt", "rw"); 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 channel of the file System.out.println(raf.getChannel()); // close the strea and release resources raf.close(); } catch (IOException ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { File outputFile = new File("test.txt"); try (FileChannel fileChannel = new FileOutputStream(outputFile).getChannel()) { String text = getText();/*from w w w . ja va2 s. c om*/ byte[] byteData = text.toString().getBytes("UTF-8"); ByteBuffer buffer = ByteBuffer.wrap(byteData); fileChannel.write(buffer); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { char[] c = { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm' }; Writer writer = new PrintWriter(System.out); try {/* w w w . j av a 2 s . c om*/ // write a portion of a char array writer.write(c, 0, 5); // flush the writer writer.flush(); // write another portion of a char array writer.write(c, 5, 5); // flush the stream again writer.close(); } catch (IOException ex) { ex.printStackTrace(); } }