자바 .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 파일 않에는 이름 숫자 이름 숫자 이런 순서대로 있어요

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 상황은 알겠습니다만...질문이 뭔가요? 정영훈 2018.2.19 15:05

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)