Tuesday, 15 April 2014

java - Is there a way to choose a specific line from file and change strings or int, double in console? -



java - Is there a way to choose a specific line from file and change strings or int, double in console? -

i've trying take specific line file , sort of got it, can't think of way alter strings or ints in console. illustration there name , age: tom 19 jennifer 22

i take line number 1 , want alter like, making tom older, can't figure out, please help. sorry waisting time if it's easy. give thanks you.

filereader fr = null; linenumberreader lnr = null; string str; int i; int currline = 1; system.out.print("which line print?: "); scanner scan = new scanner(system.in); int d = scan.nextint(); // create new reader fr = new filereader("test.txt"); lnr = new linenumberreader(fr); // read lines till end of stream while ((str = lnr.readline()) != null) { if (currline == d) { // if current line number 4, print // prints string system.out.println(str); } currline++; } // closes stream , releases scheme resources if (fr != null) fr.close(); if (lnr != null) lnr.close(); }

inside while loop, utilize filewriter modify content searching , replacing string or int.

try implementing code provided in this link. can help finish looking for

java

No comments:

Post a Comment