-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPopulationStatistics.java
More file actions
77 lines (63 loc) · 2.41 KB
/
PopulationStatistics.java
File metadata and controls
77 lines (63 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package Date10_07.Project;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class PopulationStatistics {
static String address = "C:\\Users\\qowhx\\OneDrive\\바탕 화면\\인구\\2021_인구관련연간자료_20221006_47106.csv";
public static void ReadByChar() throws IOException{ // 1글자씩 읽기
FileReader fileReader = new FileReader(address);
String fileContents ="";
while(fileContents.length()<1_000_000) {
char c = (char) fileReader.read(); // read()는 반환을 int형으로 하기 때문에 형변환이 필요
fileContents += c;
System.out.println(fileContents);
}
System.out.println(fileContents);
}
public static String ReadByOneLine() throws IOException{ // 1줄 읽기
BufferedReader reader = new BufferedReader(
new FileReader(address)
);
String str = reader.readLine();
reader.close();
return str;
}
public static void ReadByLine() throws IOException{ // 1줄씩 전부 읽기
BufferedReader reader = new BufferedReader(
new FileReader(address)
);
String str;
while ((str = reader.readLine()) != null) {
System.out.println(str);
}
reader.close();
}
public static void ReadByLine2() { // 1줄씩 전부 읽기 (2)
try (BufferedReader br = Files.newBufferedReader(
Paths.get(address), StandardCharsets.UTF_8)) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
public static PopulationMove parse(String data) throws IOException {
String[] str = data.split(",");
int FromSido = Integer.parseInt(str[0]);
int ToSido = Integer.parseInt(str[6]);
return new PopulationMove(FromSido,ToSido);
}
public static void main(String[] args) throws IOException {
// ReadByChar();
// ReadByLine();
// ReadByLine2();
System.out.println(parse(ReadByOneLine()));
}
}