import java.io.*; public class FileOutputStreamDemo { public static void main(String[] args) { FileOutputStream fos = null; FileInputStream fis = null; try{ fis = new FileInputStream("FileOutputStreamDemo.java"); fos = new FileOutputStream("out.txt"); int c = fis.read(); while(c != -1) { fos.write((char)c); c = fis.read(); } } catch(IOException ie) { ie.printStackTrace(); } finally { try { if(fis != null) fis.close(); }catch(IOException ie){ ie.printStackTrace(); } try { if(fos != null) fos.close(); }catch(IOException ie){ ie.printStackTrace(); } } } } import java.io.*; public class FileOutputStreamDemo2 { public static void main(String[] args) { try(FileInputStream fis = new FileInputStream("FileOutputStreamDemo2.java"); FileOutputStream fos = new FileOutputStream("out2.txt", true); ) { int c = fis.read(); while(c != -1) { fos.write((char)c); c = fis.read(); } } catch(IOException ie) { ie.printStackTrace(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter