使用扫描仪读取文本文件
/* from N o w J a v a . c o m */ import java.io.File; import java.io.IOException; import java.util.Scanner; public class Part1 { public static void main(String[] args) throws IOException{ new Part1().start(); } public void start() throws IOException { File inFile = new File ("src/day04/input.txt"); Scanner sc = new Scanner (inFile); while (sc.hasNext()) { String line = sc.nextLine(); /* from nowjava - 时代Java*/ System.out.print( line.substring(0, (line.indexOf('[')-3) ) +" : "); System.out.print( line.substring((line.indexOf('[')-3), line.indexOf('[') ) +