Skip to content

Instantly share code, notes, and snippets.

@Getaji
Created July 28, 2014 15:54
Show Gist options
  • Save Getaji/0492fc09aef7579523b7 to your computer and use it in GitHub Desktop.
Save Getaji/0492fc09aef7579523b7 to your computer and use it in GitHub Desktop.
Scannerで改行をそのまま入れるよ! 速度は知らん。→計測したところ、改行文字を手動挿入するのと同じか若干早い模様です。やったね。
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new FileInputStream("src/sample.txt")).useDelimiter(Pattern.compile("^"));
StringBuilder builder = new StringBuilder();
while (scanner.hasNext()) {
builder.append(scanner.next());
}
System.out.println(builder.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment