import java.io.*; public class Main { public static void main(String[] args) { BufferedInputStream in = null; BufferedOutputStream out = null; try { in = new BufferedInputStream(new FileInputStream("in.txt")); out = new BufferedOutputStream(new FileOutputStream("out.txt")); for(int i = in.read(); i != 'O'; i = in.read()) { out.write(i); } out.flush(); } catch (IOException ex) { System.out.println(ex); } finally { try { if(in != null) { in.close(); } if(out != null) { out.close(); } } catch (IOException ex) { System.out.println(ex); } } } }