String が特定の文字で始まるかどうかを判断する Java の組み込みメソッドはありますか? 定義された文字で始まらない行だけを出力ファイルに書き込むにはどうすればよいですか?
try {
File input = new File("input");
File output = new File("output");
Scanner sc = new Scanner(input);
PrintWriter printer = new PrintWriter(output);
while (sc.hasNextLine()) {
String s = sc.nextLine();
printer.write(s);
}
printer.flush();
}
catch (FileNotFoundException e) {
System.err.println("File not found. Please scan in new file.");
}