java - How to append 4 digit number to the next string read from file -
i have 1 file read this
mytxt.txt
1234 http://www.abc.com 8754 http://www.xyz.com
i tried this
try { // make 'file' object file file = new file("e:/mytxt.txt"); // data file using file reader. filereader fr = new filereader(file); // store contents read via file reader bufferedreader br = new bufferedreader(fr); // read br , store line in 'data', print data string data; while((data = br.readline()) != null) { //data = br.readline( ); system.out.println(data); } } catch(ioexception e) { system.out.println("bad !"); }
i used actual question want read 1 2 charachter 1 one , appens digit link i'll read string. can tell me how suppose that..? appreciated.
parse line reading, search first white space (i'm assuming have 1 space separating digit , url) this:
try { // make 'file' object file file = new file("e:/mytxt.txt"); // data file using file reader. filereader fr = new filereader(file); // store contents read via file reader bufferedreader br = new bufferedreader(fr); // read br , store line in 'data', print data string data; while((data = br.readline()) != null) { int poswhite = data.indexof(' '); string digit = data.substring(0, poswhite); string url = data.substring(poswhite + 1); system.out.println(url + "/" + digit); } } catch(ioexception e) { system.out.println("bad !"); }
Comments
Post a Comment