windows - Java add line to specific part of text file -


comments below answering question, way me ask new question...

okay. program writing info on .txt file. writing info end of text file so:

t/1/15/12 o/1/12/3 o/2/15/8 ... (lots of lines this.. different numbers) o/1/16/4 

then.. when add line using:

bufferedwriter fw = new bufferedwriter(new filewriter(new file("c://users/mini/desktop/eclipse/japda/map/" +numbers.map +".txt"), true));             fw.newline();             fw.write(rightpanel.mode.charat(0) +"/" +id +"/" +numbers.middlex +"/" +numbers.middley);             fw.close(); 

it adds line want end of text file.. write line specific part of text files.. know number of line want write it.. (it calculated depending on other lines..) :d there way it? or best way edit 1 specific line in middle of text file?

to achieve require, need use randomaccessfile. steps: first create randomaccessfile then:

  1. create variable called linestart set 0 (beginning of file)

  2. read in file line line using readline

  3. check whether required line wish insert before

  4. if correct place, linestart hold position before line wish insert before. use seek position @ correct place using seek(0) position @ start of file, seek(linestart) required position. use writechars write file. remember have explicitly write newline.

  5. if not wish insert call getfilepointer, , store value in linestart

repeat steps 2-5 until arrive @ desired place insertion


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -