Copy all mobile Number From a text file java code error -


exception in thread "main" java.lang.stringindexoutofboundsexception: string index out of range: 10     @ java.lang.string.charat(unknown source)     @ pdftoexcel.fileread.mobile_number(fileread.java:15)     @ pdftoexcel.fileread.remove_other(fileread.java:45)     @ pdftoexcel.fileread.main(fileread.java:65)   import java.io.*;  public class fileread {    public static void mobile_number (string line){     int len = line.length();     try{         for(int i=0;i<len;i++){             string res = "88";             if(line.charat(i)=='0' && line.charat(i+1)=='1'){                 if(line.charat(i+2)>='5' && line.charat(i+2)<='9' ){                     if((line.charat(i+10)>='0' && line.charat(i+10)<='9')){                         res+="01"+line.charat(i+2)+"1";                         res+= line.substring(i+3, i+10);                     }else if((line.charat(i+11)>='0' && line.charat(i+11)<='9')){                         res+= line.substring(i, i+11);                     }                   }else if(line.charat(i+2)=='1' && line.charat(i+3)=='9') {                         if((line.charat(i+10)>='0' && line.charat(i+10)<='9')){                             res+="01191";                             res+= line.substring(i+4, i+10);                         }else if((line.charat(i+11)>='0' && line.charat(i+11)<='9')){                             res+= line.substring(i, i+11);                         }                  }             }             if(res.length()>9) system.out.println(res);         }     }finally{      } }   public static void remove_other(string l){     string str="";     for(int i=0;i<l.length();i++){         if(l.charat(i)>='0' && l.charat(i)<='9'){             str+=l.charat(i);         }         if(str.length()>9) mobile_number(str);     } }    public static void main(string[] args) throws ioexception {       file f=new file("c:\\users\\user\\desktop\\abc.txt");      bufferedreader br = new bufferedreader(new filereader(f));     try {         stringbuilder sb = new stringbuilder();         string line = br.readline();         while (line != null) {             sb.append(line);             sb.append(system.lineseparator());             line = br.readline();             if(line.length()>9){                 remove_other(line);             }             //system.out.println(line);             //system.out.println(">>>>>>>>>>>>>>> " + line.length());          }         string = sb.tostring();     } {         br.close();     }    }  } 

you use 'i' iteration counter, , grows line.length:

int len = line.length(); for(int i=0;i<len;i++){...} 

imagine happens when 'i' @ point equals line.length -1 , encounters such instruction as

if(line.charat(i+10) == '9') {...} 

e.g. when line.length = 10 try 19-th character of it.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -