Javatpoint Logo
Javatpoint Logo

Java FileOutputStream write() Method

The write(byte[] b) method of FileOutputStream class is used to write b.length bytes from the specified byte array to this file output stream.

Syntax

Parameter

b - the data.

Return Value

This method does not return any value.

Exception

IOException - If any I/O error occurs.

Example 1

Output:

Enter  5 byte to write into a file
23
67
65
55
45
You Enter  5  byte successfully
byte that you enter into the File is
  23    67    65    55    45  

Example 2

Output:

byte's ---->23,45,67,78,98,67<--->that is  write into a file<---->
successfully write byte's into a file
byte that you enter into the File is

  23    45    67    78    98    67  

Example 3

Output:

byte's ---->23,45,67,78,98,67<--->that is  write into a file<---->
successfully write byte's into a file

character value of that byte's  that you enter into the File is

  !    7    B    N    Z  

Java FileOutputStream write(byte[] b, int off, int len) Method

The write(byte[] b, int off, int len) method of Java FileOutputStream class is used to write data from the given maximum length(len) of the data starting from the given offset.

Syntax

Parameter

b - The data.

off - The start offset in the data.

slen - The number of bytes to write.

Return Value

This method does not return a value.

Exception

IOException - If an I/O error occurs.

Example 1

Output:

byte's ----> 23 ,45 ,67 ,78 ,98 ,67 <--->that is  write into a file<---->
successfully write byte's into a file---> 2 index position  to 3 index position.
byte that you enter into the File is

  67    78    98  

Example 2

Output:

byte's ---->23,45,67,78,98,67<--->that is  write into a file<---->
write byte' from 2 index position to the next 2 postion

successfully write byte's into a file

character value of that byte's  that you enter into the File is

  B    N  

Java FileOutputStream write(int b) Method

The write(int b) method of Java FileOutputStream class is used to write the specified byte to this file output stream.

Syntax

Parameter

b - The byte.

Return Value

This method does not return a value.

Exception

IOException - If an I/O error occurs.

Example 1

Output:

Enter a  byte to write into a file
23
you enter  byte successfully
byte that you enter into the File is
 23  

Example 2

Output:

Enter  byte to write into a file
34
you enter  byte successfully
 convert a byte into a character that is





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA