Welcome to Java Examples

Take a cup of tea and Let's Start programming

FileOutputStream  in java


import java.io.*; class fileoutputstrm { public static void main(String[] args) throws Exception { byte data[]="hi... this is a program of fileoutputstream class".getBytes(); //method to write using loop FileOutputStream fileoutputstrm1 = new FileOutputStream("file1.txt"); for(int index_loop=0;index_loop<data.length;index_loop++) { fileoutputstrm1.write(data[index_loop]); } //method to write using write() method FileOutputStream fileoutputstrm2 = new FileOutputStream("file2.txt"); fileoutputstrm2.write(data); //method to write from specific byte to specific point FileOutputStream fileoutputstrm3 = new FileOutputStream("file3.txt"); fileoutputstrm3.write(data,5,15); //close all files fileoutputstrm1.close(); fileoutputstrm2.close(); fileoutputstrm3.close(); } }




















output

it will create 3 .txt file


0 comments :

Post a Comment