java - Open a text file and find a word and point to that word -



java - Open a text file and find a word and point to that word -

i need open log file (.txt) , go specific word.

ex:- if im searching "mytextword" in text file, should open default editor , go word "mytextword".

if it's in 100th line should go there, shows 100th line , onwards.

can done linux , windows?

i think, past few days developing simple project involved same thing.

you can utilize scanner scan file data. , loop through data.

i paste code here , share post link you, if need farther info, can there.

you can pass string parameter method.

string character = sc.next(); // read character... // find character system.out.println("searching now..."); getcharacterlocation(character); // here parameter character

file reading function below:

file file = new file("res/file.txt"); scanner sc = new scanner(file); int linenumber = 0; int totallines = 0; boolean found = false; // first total number of lines while(sc.hasnextline()) { totallines++; sc.nextline(); system.out.println("line looping! total lines variable."); } int[] linenumbers = new int[totallines]; int lineindex = 0; system.out.println("searching in each line..."); sc.close(); sc = new scanner(file); while(sc.hasnextline()) { // until end /* each of character, mean string * each of line... */ string characterinline = sc.nextline().tolowercase(); if(characterinline.indexof(character.tolowercase()) != -1) { found = true; } linenumber++; if(sc.hasnextline()) sc.nextline(); } system.out.println("searching complete, showing results..."); // done! post that. if(found) { // found! :d system.out.print("'" + character + "' found in file!"); } else { // nope didn't found fuck! system.out.println("sorry, '" + character + "' didn't match character in file ."); } sc.close();

yes, know bit messed code, because writing comments , info of ever process beingness executing , has done executing.

to whole code this, go link below.

http://basicsofwebdevelopment.wordpress.com/2014/05/27/scanning-file-for-particular-string-or-character-searching/

java text

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -