从文本中读取 并截取须要的字符串

   //按行读取文本 java

String FileName="d:/txt.txt"; 字符串

        File myFile=new File(FileName);
        try
        {
          BufferedReader in = new BufferedReader(new FileReader(myFile));
            String str;
            while ((str = in.readLine()) != null&& in.readLine() != "")
            {    
                String N = str;    
                for (int i = 0; i < N.length()-1; i++) { //循环读取文本的每一行
                    String string = "**";
                    if (str.substring(i, i+2).equals(string)) {//跟进须要截取所须要的字符串
                        System.out.println(str.substring(i+2,  N.length()));
                    }
                }
                
            }
            in.close();
        }
        catch (IOException e)
        {
            e.getStackTrace();

        } get

注意 若是substring(index1,index2)中的index2若是大于str.length()+1则会报出异常java.lang.StringIndexOutOfBoundsException: String index out of range string

相关文章
相关标签/搜索