我有一个包含以下数据的日志文件:
最短路径(2):: RV3280-RV0973C-RV2888C
最短路径(1):: RV3280-RV2502C
最短路径(2):: RV3280-RV2501C-RV1263
最短路径(2):: RV2363-Rv3285-RV3280
从每一行,我需要括号内的数字,第一个蛋白质的名称(第一行中的RV3280)和最后一个蛋白质的名称(第一行中的RV2888C).
我用这个Scanner对象编写了一个代码.
try{
Scanner s = new Scanner(new File(args[0]));
while (s.hasNextLine()) {
s.findInLine("Shortest path\\((\\d+)\\)::(\\w+).*-(\\w+)"); // at each line, look for this pattern
MatchResult result = s.match(); // results from
for (int i=1; i<=result.groupCount(); i++) {
System.out.println(result.group(i));
}
s.nextLine(); // line no. 29
}
s.close();
}
catch (FileNotFoundException e) {
System.out.print("cannot find file");
}
Run Code Online (Sandbox Code Playgroud)
我得到了预期的结果,但我也收到了一条错误消息.我得到的上述输入文件的输出是:
Exception in thread "main" java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Scanner.java:1516)
at nearnessindex.Main.main(Main.java:29)
2
RV3280
RV2888C …Run Code Online (Sandbox Code Playgroud) 在我正在制作的网站上,我想知道用户如何登陆特定页面(比如here.php).可能有两种可能的方法:单击page1.php上的链接或page2.php上的链接.我怎样才能知道用户是如何到达的,以便我可以根据它提供内容.