Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 1.12 KB

README.md

File metadata and controls

38 lines (33 loc) · 1.12 KB

目次 前の問題 次の問題


070:複合(10)

  • 以下は、テキストファイルを読み取り、その結果を出力するプログラムである。問題点を指摘し、修正せよ。
public class Knock070 {
    private static final Logger logger = Logger.getLogger("Knock070");

    public static void readFile() {
        FileReader reader = null;
        try {
            File file = new File("c:¥¥tmp¥¥test.txt");
            reader = new FileReader(file);
            int ch;
            while ((ch = reader.read()) != -1) {
                  System.out.print((char)ch);
            }
        } catch (FileNotFoundException e) {
            logger.log(Level.WARNING, "FileNotfound.", e);
        } catch (IOException e) {
            logger.log(Level.WARNING, "IOException.", e);
        } finally {
            try {
                if(reader != null) {
                    reader.close();
                }
            } catch(IOException e) {
                logger.log(Level.WARNING, "close error.", e);
            }
        }
    }
}