다음은
BufferedReader
와 BufferedWriter
를 사용하는 예제입니다.import java.io.*; import java.util.*; class OutputWriter { private BufferedWriter writer; public OutputWriter() { writer = new BufferedWriter(new OutputStreamWriter(System.out)); } public OutputWriter(String fileName) throws IOException { writer = new BufferedWriter(new FileWriter(fileName)); } public void print(String s) throws IOException { writer.write(s); } public void println(String s) throws IOException { writer.write(s); writer.newLine(); } public void print(int i) throws IOException { writer.write(Integer.toString(i)); } public void println(int i) throws IOException { writer.write(Integer.toString(i)); writer.newLine(); } // You can add more print methods for different data types as needed. public void close() throws IOException { writer.flush(); writer.close(); } } class InputReader { public BufferedReader reader; public StringTokenizer st; public InputReader() { reader = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(nextLine()); } return st.nextToken(); } public String nextLine() { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } public int nextInt() { return Integer.parseInt(next()); } }
작성중…