java - How to update a text file based on values within it -


i want edit values(a row values) of csv file based on specific value of row (an id). able read , write (append) values in cannot figure out how edit , delete them.

here small fragment of code doing reading file , appending values:

filewriter writer = new filewriter("file.csv", true); try {     fileinputstream fstream = new fileinputstream("file.csv");     bufferedreader br = new bufferedreader(new inputstreamreader(fstream));     string strline;                   while ((strline = br.readline()) != null) {         string[] fields = strline.split(",");         if (fields[1].equals("value") {             fields[1] = "different value";         }         writer.append(fields);     }     catch(...) } 

but can't work out how write values same spot in file.

unfortunately can't open single file both reading , writing @ same time. need read file , close before opening writing.

the potential solutions are:

  • write output different file , replace original when complete

  • keep output in internal variables then, once you've finished reading, close file , reopen writing.


Comments

Popular posts from this blog

How to access named pipes using JavaScript in Firefox add-on? -

multithreading - OPAL (Open Phone Abstraction Library) Transport not terminated when reattaching thread? -

node.js - req param returns an empty array -