ANTLRInputStream 和 ANTLRFileStream 已弃用,有哪些替代方案?

ANTLRInputStream and ANTLRFileStream are deprecated, what are the alternatives?

如果我使用

ANTLRFileStream antlrFileStream = new ANTLRFileStream("myfile.testlang");

ANTLRInputStream input = new ANTLRInputStream( new FileInputStream("myfile.testlang") );

编译器显示两者的弃用错误 类 什么是替代方案?

您可以使用 CharStreams class 代替下面已弃用的 class。

CharStream codePointCharStream = CharStreams.fromFileName("myfile.testlang");
TESTLANGLexer lexer = new TESTLANGLexer(codePointCharStream);
TESTLANGParser parser = new TESTLANGParser(new CommonTokenStream(lexer));
parser.addParseListener(new TESTLANGEventListener());

// Start parsing
parser.testlangFile();