import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import java.io.*;
public class BufferOutputStreamrExample {
public static void main(String[] args) throws FileNotFoundException, IOException {
FileOutputStream file = new FileOutputStream("F:\\check.txt");
BufferedOutputStream bout = new BufferedOutputStream(file); //collection of data //here it is now connected to fileoutputStream to flush large amount of data together
String s = "shashi is not dead";
byte b[] = s.getBytes();
bout.write(b);
bout.flush();//it is used for flushing the buffer output stream data .
bout.close();
file.close();
}
*********************************************************************************
// whereas in byte array output stream we can write it to a different file
public static void main(String[] args) throws FileNotFoundException, IOException {
FileOutputStream file = new FileOutputStream("F:\\check.txt");
ByteArrayOutputStream bout1 = new ByteArrayOutputStream();
bout1.write(65); // byte gives the ascii code so 65==A
bout1.writeTo(file);
// like bout.writeTo(file1);
}
*********************************************************************************
public static void main(String[] args) throws FileNotFoundException, IOException {
FileInputStream file = new FileInputStream("F:\\check.txt");
BufferedInputStream bin = new BufferedInputStream(file); //collection of data //here it is now connected to fileoutputStream
int i=0 ;
while((i=bin.read())!=-1)
{
char ch =(char)i;
System.out.println(ch);
}
bin.close();
file.close();
}
******************************************************************************
public static void main(String[] args) throws FileNotFoundException, IOException {
byte []g = {35,37,38}; // be spefic while using byte as it has differnt code for different symbols.
ByteArrayInputStream bin = new ByteArrayInputStream(g);// it will only read the byte data
int i=0 ;
while((i=bin.read())!=-1)
{
char ch =(char)i;
System.out.println(ch);
}
}
output :- #
%
&
*******************************************************************************
}
No comments:
Post a Comment