write(byte[]): This method is available in the java.io.FileOutputStream class of Java.
Syntax:
void java.io.FileOutputStream.write(byte[] b) throws IOException
This method takes one argument. This method writes b.length bytes from the specified byte array to this file output stream.
Parameters: One parameter is required for this method.
b: the data.
Returns: NA
Throws:
IOException - if an I/O error occurs.
Approach
Java
import java.io.File;import java.io.FileOutputStream;import java.io.IOException;public class FileOutputStreamwrite {public static void main(String[] args) throws IOException {String pathname = "D:\\hello.txt";File file = new File(pathname);FileOutputStream fileOutputStream =new FileOutputStream(file);byte b[] = { 'a', 'b', 'c', 'd' };fileOutputStream.write(b);System.out.println("Successfully writes");fileOutputStream.close();}}
Output:
Successfully writes
No comments:
Post a Comment