-
Notifications
You must be signed in to change notification settings - Fork 207
Expand file tree
/
Copy pathTask03Main.java
More file actions
29 lines (22 loc) · 1.07 KB
/
Task03Main.java
File metadata and controls
29 lines (22 loc) · 1.07 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
package com.example.task03;
import java.io.*;
import java.nio.charset.Charset;
public class Task03Main {
public static void main(String[] args) throws IOException {
//здесь вы можете вручную протестировать ваше решение, вызывая реализуемый метод и смотря результат
// например вот так:
/*
System.out.println(readAsString(new FileInputStream("task03/src/com/example/task03/input.test"), Charset.forName("KOI8-R")));
*/
}
public static String readAsString(InputStream inputStream, Charset charset) throws IOException {
if(inputStream == null || charset == null) throw new IllegalArgumentException();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charset));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = reader.readLine()) != null){
stringBuilder.append(line);
}
return stringBuilder.toString();
}
}