0

Hi sorry for bad things.

this is a text file

[TESTRESULT]
testdate=5/16/2013
testtime=20:03:00
operator=Jacob Poulsen
test_no=62495
axles_tested=2
[AXLE1RESULT]
fric_l=38
fric_r=51
p0_l=0
p0_r=0
fl=280
fr=300

So i find issue for first find string ex:
second append text before [AXLE1RESULT]
Like this

[TESTRESULT]
testdate=5/16/2013
testtime=20:03:00
operator=Jacob Poulsen
test_no=62495
axles_tested=2
[SomeText]
Something=0
Something=0
Something=0
[AXLE1RESULT]
fric_l=38
fric_r=51
p0_l=0
p0_r=0
fl=280
fr=300

What should i do???

BilguunKH
  • 3
  • 4
  • I can't quite tell what you are asking; but these files are formatted as Windows INI files. Perhaps http://stackoverflow.com/questions/190629/what-is-the-easiest-way-to-parse-an-ini-file-in-java will help (ini4j can read, parse, and write them, and will let you easily modify values). – Jason C Mar 25 '14 at 06:36

2 Answers2

0

Better read it from one file and write it another file. If you want to append some text check for the occurrence and append it. Once you done with your process delete the original file.

Shriram
  • 4,343
  • 8
  • 37
  • 64
0

This should solve your problem:

BufferedReader br= new BufferedReader(new FileReader("yourfilename.txt"));
String dataRow=null;
string tempText="";
while ( (dataRow= br.readLine()) dataRow != null){
    if(dataRow.equalsIgnoreCase("[AXLE1RESULT]"){
        tempText+="[SomeText]";
        tempText+=System.getProperty("line.separator");
        tempText+="Something=0";
        tempText+=System.getProperty("line.separator");
        tempText+="Something=0";
        tempText+=System.getProperty("line.separator");
        tempText+="Something=0";
        tempText+=System.getProperty("line.separator");
    }
    tempText+=dataRow;
    tempText+=System.getProperty("line.separator");
}

FileWriter writer = new FileWriter("yourfilename.txt");
writer.append(tempText);    
writer.flush();
writer.close();
Baby
  • 5,062
  • 3
  • 30
  • 52