回答編集履歴
2
コード修正
test
CHANGED
@@ -150,7 +150,7 @@
|
|
150
150
|
|
151
151
|
if(nums.contains(i)) {
|
152
152
|
|
153
|
-
System.out.print(line);
|
153
|
+
System.out.println(line);
|
154
154
|
|
155
155
|
pw.println(line);
|
156
156
|
|
1
追加
test
CHANGED
@@ -69,3 +69,107 @@
|
|
69
69
|
}
|
70
70
|
|
71
71
|
```
|
72
|
+
|
73
|
+
---
|
74
|
+
|
75
|
+
**追加**
|
76
|
+
|
77
|
+
行を一つずつ指定する場合です.
|
78
|
+
|
79
|
+
```java
|
80
|
+
|
81
|
+
import java.io.BufferedReader;
|
82
|
+
|
83
|
+
import java.io.FileReader;
|
84
|
+
|
85
|
+
import java.io.FileWriter;
|
86
|
+
|
87
|
+
import java.io.IOException;
|
88
|
+
|
89
|
+
import java.io.PrintWriter;
|
90
|
+
|
91
|
+
import java.util.ArrayList;
|
92
|
+
|
93
|
+
import java.util.List;
|
94
|
+
|
95
|
+
import java.util.Scanner;
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
public class aaa {
|
100
|
+
|
101
|
+
public static void main(String[] args) {
|
102
|
+
|
103
|
+
String inFilename = "D:\Book3.csv";
|
104
|
+
|
105
|
+
String outFilename = "D:\normdist_結果3.csv";
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
//入力
|
110
|
+
|
111
|
+
List<Integer> nums = new ArrayList<>();
|
112
|
+
|
113
|
+
try(Scanner scanner = new Scanner(System.in);) {
|
114
|
+
|
115
|
+
int v;
|
116
|
+
|
117
|
+
while(true) {
|
118
|
+
|
119
|
+
System.out.print("抜き出したい行は?(1以上を指定, 0以下で終了) :");
|
120
|
+
|
121
|
+
v = scanner.nextInt();
|
122
|
+
|
123
|
+
if(v <= 0) break;
|
124
|
+
|
125
|
+
nums.add(v);
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
if(nums.size() == 0) {
|
132
|
+
|
133
|
+
System.out.print("抜き出しませんでした.");
|
134
|
+
|
135
|
+
System.exit(0);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
//抽出
|
142
|
+
|
143
|
+
try(BufferedReader br = new BufferedReader(new FileReader(inFilename));
|
144
|
+
|
145
|
+
PrintWriter pw = new PrintWriter(new FileWriter(outFilename));) {
|
146
|
+
|
147
|
+
String line;
|
148
|
+
|
149
|
+
for(int i=1; (line=br.readLine()) != null; i++) {
|
150
|
+
|
151
|
+
if(nums.contains(i)) {
|
152
|
+
|
153
|
+
System.out.print(line);
|
154
|
+
|
155
|
+
pw.println(line);
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
System.out.print("抜き出しました.");
|
162
|
+
|
163
|
+
} catch(IOException e) {
|
164
|
+
|
165
|
+
e.printStackTrace();
|
166
|
+
|
167
|
+
System.exit(1);
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
}
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
```
|