java - How to replace the star {*} in text file with a number -


my contents of text file looks this

synonyms of fluster:

*panic

*perturb

*disconcert

*confuse ......

now wish replace * numbers.something this.

output

synonyms of fluster:

1)panic

2)perturb

3)disconcert

4)confuse ......

edit:

integer count = 1;      file input = new file("c:\\sample.txt");      file output = new file("c:\\output.txt");       bufferedreader reader = new bufferedreader(new inputstreamreader(new fileinputstream(input)));      writer writer =new filewriter(output);       while((line=reader.readline())!=null)       {           if(line.contains("*"))           {               line.replace("*",count.tostring() );               writer.write(line);               count++;           }            else           {               writer.write(line);           }       } 

this had tried before posting question here..but doesn't seem work. can me out..?

you should write java program.

here's may started (rough code):

bufferedreader br = new bufferedreader(new filereader(file));  //start reading file line-by-line while ((line = br.readline()) != null) {      //replace * whatever want     // use counter keep track of lines give corresponding line number     string val = line.replace("*",countervar.tostring());  } br.close(); 

write file using bufferedwriter again, wrap printwriter if wish to,

printwriter out = new printwriter(new bufferedwriter(new filewriter("outputfile"))); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -