write(byte[], int, int): This method is available in the java.io.DataOutputStream class of Java.
Syntax:
void java.io.DataOutputStream.write(byte[] b, int off, int len) throws IOException
This method takes three arguments. This method writes len bytes from the specified byte array starting at offset off to the underlying output stream.
Note: If no exception is thrown, the counter written is incremented by len.
Parameters: Three parameters are required for this method.
b: the data.
off: the start offset in the data.
len: the number of bytes to write.
Throws:
IOException - if an I/O error occurs.
Approach
Java
import java.io.DataOutputStream;import java.io.FileOutputStream;import java.io.IOException;public class DataOutputStreamwrite3 {public static void main(String[] args) throws IOException {FileOutputStream file =new FileOutputStream("D:\\hello.txt");DataOutputStream data = new DataOutputStream(file);byte b[] = { 65, 67, 68, 70, 71, 72, 73 };int off = 0, len = 5;data.write(b, off, len);System.out.println("Successfully writes");data.close();}}
Output:
Successfully writes
hello.txt
ACDFG
No comments:
Post a Comment