Добавил:
Upload
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Java_Лекция 2 / 15_IO_Examples / src / InputExample
.javaimport java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class InputExample {
public static void main(String[] args) throws IOException {
// How to read from Console
// Case 1: use Reader and InputStreamReader
BufferedReader in;
// if you work under Windows console which has Cp866 encoding
in = new BufferedReader(
new InputStreamReader(
System.in, // <=== data source
"Cp866")); // <=== this way we point encoding
// if you work under Eclipse's console which has Cp1251 encoding
in = new BufferedReader(
new InputStreamReader(
System.in)); // <=== data source has Cp1251 encoding
// OR you can directly set source encoding
in = new BufferedReader(
new InputStreamReader(
System.in, // <=== data source
"Cp1251")); // <=== data source encoding
String s = null;
// this way we get info from the input
while ((s=in.readLine()) != null) {
System.out.println(s);
}
// Type any string and press ENTER
// Type Ctrl+Z to exit
}
}
Соседние файлы в папке src