Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

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;

while(n-->0){ //Check that


n is not equal to zero before decrementing it

FileReader fr=new FileReader("C:\\Users\\MUJI SHAIK\\Documents\\TCS\\


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("@");

while((str = br.readLine())!= null){ //if not


zero read string line by line

if((str.startsWith("<head:BizMsgldr>"))&&(str.endsWith("</head:BizMsgidr>")))
{

pw.println("<head:BizMsgldr>"+rand()+"</head:BizMsgidr>");

}
else{

pw.println(str); //if string


contents not equal print string
}
}
br.close();
}
pw.close();
sc.close();
}

You might also like