小编use*_*125的帖子

为什么会出现java.lang.IllegalArgumentException?

java.lang.IllegalArgumentException每当我运行它时,我的程序就会打印出来.它用不同的表达式替换某些模式,包括匹配的模式中的组.它取代了部分模式,然后出现此错误:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal group reference
    at java.util.regex.Matcher.appendReplacement(Matcher.java:713)
    at RealReadFile.main(RealReadFile.java:93)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.FileNotFoundException;
import java.io.File;

public class RealReadFile {
    private static final String fileName = "KLSadd.tex";
    private Scanner myFile = null;

    public RealReadFile() throws FileNotFoundException {
        if (myFile == null)
            myFile = new Scanner(new File(fileName));
    }

    public RealReadFile(String name) throws FileNotFoundException {
        if (myFile != null)
            myFile.close();
        myFile = new Scanner(new File(name));
    }

    public boolean endOfFile() { 
        return !myFile.hasNext(); 
    } …
Run Code Online (Sandbox Code Playgroud)

java regex exception illegalargumentexception regex-group

1
推荐指数
1
解决办法
2158
查看次数