Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.nio.charset.StandardCharsets;
- public class FastScanner implements AutoCloseable {
- InputStreamReader reader;
- boolean skipn;
- int cur;
- public FastScanner(FileInputStream fileInputStream) throws IOException {
- skipn = (System.lineSeparator().length() == 2);
- reader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
- cur = reader.read();
- }
- public String readLine() throws IOException {
- StringBuilder sb = new StringBuilder();
- boolean eol = false;
- do {
- if ((cur == '\r') || (cur == '\n')) {
- eol = true;
- break;
- }
- sb.append((char) cur);
- } while ((cur = reader.read()) != -1);
- if (eol) {
- if (skipn) {
- cur = reader.read();
- }
- }
- return sb.toString();
- }
- public boolean hasNextLine() throws IOException {
- return cur != -1;
- }
- public void close() throws IOException {
- if (reader != null) {
- reader.close();
- }
- }
- public static void main(String[] args) throws IOException {
- FastScanner in = new FastScanner(new FileInputStream("Test.txt"));
- PrintWriter out = new PrintWriter(new File("output.txt"), "utf8");
- out.println(in.readLine());
- out.close();
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement