Writing common data to multiple files using ByteArrayOutputStream


// Java ByteArrayOutputStream class is used to write common data into multiple files.
// In this stream, the data is written into a byte array which can be written to
// multiple streams later.
// The ByteArrayOutputStream holds a copy of data and forwards it to multiple streams.
// The buffer of ByteArrayOutputStream automatically grows according to data.

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

class ByteArrayOutputStreamDemo {

public static void main(String[] args)
throws FileNotFoundException, IOException {
FileOutputStream fos1 = new FileOutputStream("a.txt");
FileOutputStream fos2 = new FileOutputStream("b.txt");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String s = "I am learning Input Output Stream";
byte b[] = s.getBytes();
baos.write(b);
baos.writeTo(fos1);
baos.writeTo(fos2);
baos.flush();
baos.close();
fos1.close();
fos2.close();
System.out.println("Data copied in both files Successfully");
}
}

Google Script for Data Entry Form in Google Spreadsheet

// function to validate the entry made by user in user form function validateEntry (){ // declare a variable and referernece of active goog...