자바 I/O 파일 (made by Petr Mitrichev)IT/Java2018. 2. 4. 19:33
Table of Contents
Java I/O file made by Petr Mitrichev
- 특징 : scanner가 아닌 stream을 이용하기 때문에 성능이 좋다
import java.io.*;
import java.util.ArrayList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
static class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
static void setupInputOutputFile() {
try {
System.setIn(new FileInputStream(new File("resources/input.txt")));
System.setOut(new PrintStream(new File("resources/output.txt")));
} catch (Exception e) {
e.printStackTrace();
}
}
}
'IT > Java' 카테고리의 다른 글
e.printStackTrace() (0) | 2018.07.18 |
---|---|
@builder 관련 내용 (0) | 2018.03.08 |
String to char[] (0) | 2018.02.24 |
Java 환경변수 설정 이유 (0) | 2018.02.04 |
애노테이션의 한계 (0) | 2018.02.04 |
@DEAN :: Dean Story
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!