Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose a text file has following lines Twinkle, twinkle, little star, How I won

ID: 3570745 • Letter: S

Question

Suppose a text file has following lines

Twinkle, twinkle, little star,
     How I wonder what you are.
     Up above the world so high,
     Like a diamond in the sky.

write a program that will read this file and add "******" after everyline

so the file should be like this

Twinkle, twinkle, little star,

  *****
     How I wonder what you are.

  *****
     Up above the world so high,
  *****

     Like a diamond in the sky.

*****

actually i need a method for this not the whole program and if possible using has next not the buffer one

Explanation / Answer

import java.io.*;
import java.io.*;
import java.io.IOException;

class twinkle{

   public static void main(String[] args) {

       BufferedReader br = null;
       BufferedWriter wr = null;

       try {

           String sCurrentLine;

           br = new BufferedReader(new FileReader("Twinkle.txt"));
           wr = new BufferedWriter(new FileWriter("Twinkle2.txt"));

           while ((sCurrentLine = br.readLine()) != null) {
               System.out.println(sCurrentLine);
               wr.write(sCurrentLine);
               wr.write(" ****** ");
           }

       } catch (IOException e) {
           e.printStackTrace();
       } finally {
           try {
               if (br != null)br.close();
               wr.close();
           } catch (IOException ex) {
               ex.printStackTrace();
           }
       }

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote