java txt 파일 읽어서 추가로 쓰기 -> 성적처리

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class java_성적처리 {

public static void main(String[] args) throws IOException {
BufferedReader in = null;
BufferedWriter out = null;
in = new BufferedReader(new FileReader("sungjuk.txt"));


out = new BufferedWriter(new FileWriter("sungjuk1.txt"));
String line;

while((line = in.readLine()) != null){
String[] tokens = line.split(" ");
int sum = Integer.parseInt(tokens[1]) + Integer.parseInt(tokens[2]) + Integer.parseInt(tokens[3]);
line = line + " " + sum;
out.write(line);
out.newLine();
//System.out.println(line);
}
in.close();
out.close();
}

}



                        결과
                        이름 점수 점수 점수 형식에서
                        이름 점수 점수 점수  점수의 합계로
                        sungjuk.txt -> sungjuk1.txt






댓글

이 블로그의 인기 게시물

About Kafka Basic

About JVM Warm up

About idempotent

About G1 GC

About ZGC

Spring Boot Actuator readiness, liveness probes on k8s

sneak peek jitpack

Optimistic Concurrency Control VS Pessimistic Concurrency Control - What should i choose?

DDD(Domain Driven Design) - Aggregate (어그리게잇)

Strategy Pattern In Spring (feat. JPA)