FileOutputStream, FileWriter 뭔 가지각색이 있는데 알고리즘을 할 떄 사용하려는 입출력만 정리했다.

출력을 엄청 많이해서 시간을 줄일라면

System.out.println 보다는 Bufferedwriter해서 bw.write인가 뭐시긴 가를 해야한다는데

어차피 출력은 내가 TC 만들기 편한게 좀더 커서 당분간은 이렇게 쓰려고 한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.*;
import java.io.*;
import java.math.*;
 
public class make_input {
 
    
 
    public static void main(String[] args) throws IOException {
    
        System.setIn(new FileInputStream("input.txt")); 
        // 이것을 사용하면 br.readLine()을 콘솔에서 받는것이 아닌 input.txt에서 받게 된다.
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.setOut(new PrintStream(new FileOutputStream("output.txt"))); 
        // 이것을 사용하면 System.out.println()으로 출력시 콘솔에서 받는게 아닌 output.txt에서 받게 된다.
        
 
        int a = Integer.parseInt(br.readLine()); // 콘솔이 아닌 input.txt에서 한줄 긁어온다.
        
    
        for(int i = 1 ; i <= 300 ; i++) {
            for(int j = 1 ; j <= 300 ; j++)
                System.out.print((i+j) + " "); // 콘솔이 아닌 output.txt에 출력해버린다.
                System.out.println();
        }
    }
}
 
cs

 

 

이클립스에서 input.txt, output.txt를 편하게 볼라면 어떻게 해야할까?

이걸 누르면

 

이렇게 프로젝트 폴더에 txt파일을 볼 수 있다.

+ Recent posts