2019.01.18 파일 읽어오기

2019. 1. 18. 15:02JAVA

#1 파일 읽어오기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
 
public class Hello {
    public static void main(String[] args) {
        File file = new File("input.txt");
        try {
            Scanner sc = new Scanner(file);
            while(sc.hasNextInt()) {
                System.out.println(sc.nextInt()*100);
            }
            sc.close();
        } catch (FileNotFoundException e) {
            System.out.println("파일을 읽어오는 중 오류 발생");
        }
        
        
    }//main()
 
}
cs



-> 여기서 input.txt 파일을 생성해줘야한다.