This document contains the code for a Java program that:
1. Imports necessary packages and interfaces for file handling, random number generation, and input/output operations.
2. Defines a static method "rand()" that generates a random 8-digit number and returns it in a standardized format.
3. Contains a main method that reads input from the user, opens input and output files, reads lines from the input file, generates random IDs to replace existing ones using the "rand()" method, and writes the modified lines to the output file.
3. Closes all file and input/output streams when finished.
This document contains the code for a Java program that:
1. Imports necessary packages and interfaces for file handling, random number generation, and input/output operations.
2. Defines a static method "rand()" that generates a random 8-digit number and returns it in a standardized format.
3. Contains a main method that reads input from the user, opens input and output files, reads lines from the input file, generates random IDs to replace existing ones using the "rand()" method, and writes the modified lines to the output file.
3. Closes all file and input/output streams when finished.
This document contains the code for a Java program that:
1. Imports necessary packages and interfaces for file handling, random number generation, and input/output operations.
2. Defines a static method "rand()" that generates a random 8-digit number and returns it in a standardized format.
3. Contains a main method that reads input from the user, opens input and output files, reads lines from the input file, generates random IDs to replace existing ones using the "rand()" method, and writes the modified lines to the output file.
3. Closes all file and input/output streams when finished.
package random; //package used to group related classes
import java.io.File; //import java.io.*
import java.io.FileWriter; //which means to add all the classes and interface which are already defined in io package import java.io.PrintWriter; import java.util.Random; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.*; import java.io.IOException;
public class read {
public static String rand(){ //function
Random r = new Random(); //initializes the Random class with a seed value. int num=r.nextInt(99999999); //The nextInt() is used to get the next random integer value from this random number generator's sequence. return "SBIN"+String.format("%08d",num)+"DSBA"; // to transfer back to the caller of a method }
public static void main(String[] args) throws IOException { //the main
method is not catching any exceptions, //instead it handles the IOException by throwing it to the source which invoked the main method. (IOException is the base class for exceptions thrown while accessing information using streams, files and directories.)
File file = new File("write.txt"); //Creates a
new File instance by converting the given pathname string into an abstract pathname. FileWriter fw = new FileWriter(file); // It constructs a FileWriter object given a File object PrintWriter pw = new PrintWriter(file); // to print the formatted representation of objects to the text-output stream.
Scanner sc=new Scanner(System.in); //creates an
object of Scanner class which is defined in java. util. scanner package System.out.print("Enter number of messages required:"); //prints the text on the console and the cursor remains at the end of the text at the console. int n=sc.nextInt(); //Scans the next token of the input as an int int count=1;
Utility 2\\msg.txt"); //used to read data from the file BufferedReader br=new BufferedReader(fr); // is used to read the text from a character-based input stream.
String str; //It returns
the new updated string after changing all the occurrences of oldChar with the newChar pw.print("@");