algorithm/Algorithm-Core

Fileoutput example

아르비스 2017. 4. 26. 13:21

테스트 파일 생성을 위한  sample code

import java.io.BufferedWriter;

import java.io.FileWriter;


public class Fileoutput {

public static void main(String[] args) throws Exception {

BufferedWriter bw = null;

int MAX = 1000000;

int K = 10;

int L = 10;

StringBuffer sb = new StringBuffer();

int temp;

for (int i = 1; i < MAX+1; i++) {

temp = (int)(Math.random()*10)+1;

sb.append(temp);

sb.append(" ");

}

try {

bw = new BufferedWriter(new FileWriter("res/out.txt", false));  // file명, append 여부

bw.write("10");

bw.newLine();

for (int i = 0; i < L; i++) {

bw.write(MAX+" "+K+" "+i);

bw.newLine();

bw.write(sb.toString());

bw.newLine();

}

} catch (Exception e) {

System.out.println(e);

} finally {

bw.close();

}

}

}