LoginSignup
5
7

More than 5 years have passed since last update.

Java ファイル 1 行ずつファイル読込

Last updated at Posted at 2014-01-18
Sample.java
import java.io.*;

public class Sample {
    public static void main(String[] args){
        String filename = "sample.txt";
        try (BufferedReader in = new BufferedReader(new FileReader(new File(filename)))){
            String line;
            while((line = in.readLine()) != null) System.out.println(line);
        } catch (FileNotFoundException e){ 
            e.printStackTrace();
            System.exit(-1); // 0 以外は異常終了
        } catch (IOException e){ 
            e.printStackTrace();
            System.exit(-1);
        }
    }   
}
5
7
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
7