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 ZGC

Spring Boot Actuator readiness, liveness probes on k8s

About G1 GC

sneak peek jitpack

About idempotent

C 언어 구조체의 포인터 멤버 변수

Synology NAS에 MariaDB 10에 Mysql workbench로 원격접속하기

About Websocket minimize data size and data transfer cost on cloud