Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Java_Лекция 2 / 15_IO_Examples / src / InputEncodingExample

.java
Скачиваний:
30
Добавлен:
14.04.2015
Размер:
996 б
Скачать
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class InputEncodingExample {
	public static void main(String[] args) throws IOException {
		// How to read info from the file if we know its encoding

		// Read test-1251.txt in Cp1251 encoding
		BufferedReader in = new BufferedReader(
				new InputStreamReader(
						new FileInputStream("test-1251.txt"), // <=== source file
						"Cp1251")); // <=== this way we point file encoding
		
		String s = null;
		while ((s = in.readLine()) != null) {
			System.out.println(s);
		}
		
		in.close();

		// Read test-866.txt in Cp866 encoding
		in = new BufferedReader(
				new InputStreamReader(
						new FileInputStream("test-866.txt"),
						"Cp866")); // <=== this way we point file encoding
		
		s = null;
		while ((s = in.readLine()) != null) {
			System.out.println(s);
		}
		
		in.close();

	}
}
Соседние файлы в папке src