1. InputStream (input byte stream)
InputStream is an abstract class that defines the Java streaming byte input pattern, and all methods of that class throw an Ioexceptin exception when an error occurs.
Method Description
int available () returns the number of input bytes currently readable
void Close () closes the input stream. IOException is generated if read again after closing
void mark (int numbytes) re-enters the stream with the current dot to place a flag.
Boolean marksupported () returns true if the called Stream supports mark ()/reset ()
int read ()
int read (byte buffer[])
int read (byte buffer[],int offset,int numbytes)
void Reset ()
Long Skip (Long numbytes)
2, OutputStream
void Close ()
void Flush ()
void write (int b)
void write (byte buffer[])
void Write (Byte buffer[],int offset,int numbytes)
3. FileInputStream (file input stream)
FileInputStream (String filepath)
FileInputStream (File fileobj)
4. FileOutputStream (file input stream)
FileOutputStream (String filepaht)
FileOutputStream (File fileobj)
FileOutputStream (String Filepath,boolean append)
Package Io;import java.io.*;p ublic class Streamdemo {public static void main (string[] args) {//create a file F = new ("E: \\Java\\iodemo.txt "); Writes data to a file OutputStream out = null;try {out = new FileOutputStream (f);} catch (FileNotFoundException e) {//TODO Auto-gener Ated catch Blocke.printstacktrace ();} String str = "Hello world!!"; byte b[] = Str.getbytes (); try {out.write (b);} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace () ;} try {out.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} Read file InputStream in = null;try {in = new FileInputStream (f);} catch (FileNotFoundException e) {//TODO auto-generated CATC H Blocke.printstacktrace ();} byte b1[] = new Byte[1024];int i = 0;try {i = In.read (B1);} catch (IOException e) {//TODO auto-generated catch Blocke.pri Ntstacktrace ();} try {in.close ();} catch (IOException e) {//TODO auto-generated catch Blocke.printstacktrace ();} System.out.println (New String (B1,0,i));}}
Byte Stream writes a string to the file and reads the string