자바 .dat 파일 읽기 오류
조회수 1963회
import java.io.*;
public class ScoreApplication {
public static void main(String[] args) {
File dataFile = new File("test1.dat");
FileReader in;
BufferedReader readFile;
String score;
int avgScore;
int totalScores = 0;
int numScores = 0;
try {
in = new FileReader(dataFile);
readFile = new BufferedReader(in);
while ((score = readFile.readLine()) !=null) {
numScores += 1;
System.out.println(score);
totalScores += Integer.parseInt(score);
}
avgScore = totalScores / numScores;
System.out.println("Average= " + avgScore);
readFile.close();
in.close();
} catch (FileNotFoundException e) {
System.out.println("File does not exist or could not be foung.");
System.err.println("FileNotFoundException: " + e.getMessage());
} catch (IOException e) {
System.out.println("Could not read the file.");
System.err.println("IOException: " + e.getMessage());
}
}
} .dat 파일 않에는 이름 숫자 이름 숫자 이런 순서대로 있어요
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력