質問編集履歴
2
バージョン変更の改善 画像追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -127,3 +127,17 @@
|
|
127
127
|
|
128
128
|
|
129
129
|
}
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
みなさんの改善提案に沿ってググって実行してみたのですが、バージョンを7にして適用を押しました。するとエラーが消えないのですが他に作業が必要なのでしょうか?
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+

|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+

|
1
テキストコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -19,3 +19,111 @@
|
|
19
19
|
|
20
20
|
|
21
21
|

|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
<テキストコード>
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
package chapter08;
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
import java.io.BufferedReader;
|
36
|
+
|
37
|
+
import java.io.File;
|
38
|
+
|
39
|
+
import java.io.FileNotFoundException;
|
40
|
+
|
41
|
+
import java.io.FileReader;
|
42
|
+
|
43
|
+
import java.io.IOException;
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
public class Main3 {
|
48
|
+
|
49
|
+
private static final String LINE_SEPARATOR = System.lineSeparator();
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
public static void main(String[] args) {
|
54
|
+
|
55
|
+
System.out.println(readFromFile("src/capter08/Main3.java"));
|
56
|
+
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
public static String readFromFile(String fileName) {
|
62
|
+
|
63
|
+
File file = new File(fileName);
|
64
|
+
|
65
|
+
StringBuilder sb = new StringBuilder();
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
FileReader fr = null;
|
70
|
+
|
71
|
+
BufferedReader br = null;
|
72
|
+
|
73
|
+
try {
|
74
|
+
|
75
|
+
fr = new FileReader(file);
|
76
|
+
|
77
|
+
br = new BufferedReader(fr);
|
78
|
+
|
79
|
+
String line;
|
80
|
+
|
81
|
+
while ((line = br.readLine()) != null) {
|
82
|
+
|
83
|
+
sb.append(line).append(LINE_SEPARATOR);
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
return sb.toString();
|
88
|
+
|
89
|
+
} catch (FileNotFoundException e) {
|
90
|
+
|
91
|
+
System.err.println(String.format("ファイルが見つかりません: %s", fileName));
|
92
|
+
|
93
|
+
return null;
|
94
|
+
|
95
|
+
} catch (IOException e) {
|
96
|
+
|
97
|
+
System.err.println(String.format("ファイル読み込みに失敗しました: %s", fileName));
|
98
|
+
|
99
|
+
return null;
|
100
|
+
|
101
|
+
} finally {
|
102
|
+
|
103
|
+
closeSilently(br);
|
104
|
+
|
105
|
+
closeSilently(fr);
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
private static void closeSilently(AutoCloseable target) {
|
114
|
+
|
115
|
+
if (target != null) {
|
116
|
+
|
117
|
+
try {
|
118
|
+
|
119
|
+
target.close();
|
120
|
+
|
121
|
+
} catch (Exception e) {}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
}
|