import java.io.*; import java.util.StringTokenizer; public class pakkija{ static int nr=0; static int jrk=0; public static void kirjuta(String teade){ try{ PrintWriter faili=new PrintWriter(new FileWriter("pakitud.txt",true)); faili.println(nr+" "+teade); faili.close(); }catch(Exception ex){ex.printStackTrace();} } public static void kirjuta2(String teade){ try{ PrintWriter faili=new PrintWriter(new FileWriter("pakitud.txt",true)); faili.println(teade); faili.close(); }catch(Exception ex){ex.printStackTrace();} } public static boolean kontrolli(String s){ boolean chk=false; // jrk=1; try{ BufferedReader failist = new BufferedReader(new FileReader("pakitud.txt")); String rida=failist.readLine(); while(rida!=null && chk==false){ int tyhik=rida.indexOf(" "); if(s.equals(rida.substring(tyhik+1, rida.length()))){ chk=true; jrk=Integer.parseInt(rida.substring(0, tyhik)); System.out.println("sõna:"+ rida.substring(tyhik+1,rida.length())+"indeks"+rida.substring(0, tyhik) ); //System.out.println(rida.substring(0, tyhik)); } rida=failist.readLine(); } failist.close(); }catch(Exception ex){ // ex.printStackTrace(); } return chk;} public static void main(String argumendid[]) throws IOException{ String sona=""; String pikksona=""; boolean olemas=false; try{ BufferedReader failist=new BufferedReader( new FileReader("pakkimata.txt")); String rida=failist.readLine(); while(rida!=null){ StringTokenizer st=new StringTokenizer(rida, " ,.!?", true); while(st.hasMoreTokens()){ sona=st.nextToken(); //System.out.println("siin"); if(sona.length()>1){ olemas=kontrolli(sona); if(!olemas){ kirjuta(sona); jrk=nr; nr++; pikksona=pikksona.concat(jrk+""); }else{ pikksona=pikksona.concat(jrk+""); } }else{ pikksona=pikksona.concat(sona);} } //System.out.println(pikksona); rida=failist.readLine(); } failist.close(); } catch(Exception viga){ System.out.println("Probleem lugemisel"); } System.out.println(pikksona); kirjuta2(pikksona); /*try{ PrintWriter valja=new PrintWriter(new FileWriter("pakitud.txt"),true); valja.print("-------------------------------"); valja.print(pikksona); valja.close(); } catch(Exception viga){ System.out.println("Probleem kirjutamisel"); } }*/ } }