nlp - replace conjunctions from a txt file by end of line java -
hey need code replace occurrence of conjunctions in txt file end of line. have list of conjunctions saved in txt file.i want both input file taken , conjunctions file stored in array form.then using loop wanted compare both arrays .but gives many errors.is there better way same? tried doing, shows error in loop
import java.util.list; import java.util.scanner; import java.util.logging.level; import java.util.logging.logger; import javax.swing.jfilechooser; public class toarray { private static object arrays; public static void main(string args[]) throws filenotfoundexception { string filename,path; system.out.println("select input file"); jfilechooser chooser = new jfilechooser(); chooser.showopendialog(null); file file1 = chooser.getselectedfile(); chooser.showopendialog(null); filename = file1.getname(); path= file1.getpath(); scanner sc; sc = new scanner(new file(filename)); list<string> lines = new arraylist<string>(); while (sc.hasnextline()) { lines.add(sc.nextline()); } string[] inp = lines.toarray(new string[0]); (int index=0;index<=20;index++ ){ system.out.println(inp[index]);} string remove; remove="/machintosh hd/users/vaishnavi/desktop/temp.txt"; scanner sc1; sc1 = new scanner(new file(remove)); list<string> con; con = new arraylist<string>(); while (sc1.hasnextline()) { lines.add(sc1.nextline()); } string[] conj = con.toarray(new string[0]); } stristring oldtext; for(int i=0;i<=55;i++) { for(int j=0;j<=75;j++) { if( inp[i].equals(conj[j])) { string newtext = oldtext.replaceall(inp[i], "."); filewriter writer = null; try { writer = new filewriter(path); } catch (ioexception ex) { logger.getlogger(toarray.class.getname()).log(level.severe, null, ex); } try { writer.write(newtext); } catch (ioexception ex) { logger.getlogger(toarray.class.getname()).log(level.severe, null, ex); } } } } }
please :)
to check if array contains or not try this:
if(arrays.aslist(inp).contains("something")){ //do }
Comments
Post a Comment