Created
September 11, 2016 11:54
-
-
Save ZhdanRuslan/387fb3e0662c7fc50e76893cfdf7a6d9 to your computer and use it in GitHub Desktop.
Level 38, Lesson 06, Task 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javarush.test.level38.lesson06.task01; | |
/* Улучшения в Java 7 (try-with-resources) | |
Перепиши реализации методов класса Solution. | |
Используй нововведения, касающиеся обработки исключений, которые были добавлены в Java 7. | |
*/ | |
import java.io.BufferedInputStream; | |
import java.io.FileInputStream; | |
import java.io.IOException; | |
public class Solution { | |
public void printFile1() throws IOException { | |
try (FileInputStream fileInputStream = new FileInputStream("file.txt")){ | |
int data = fileInputStream.read(); | |
while (data != -1) { | |
System.out.println(data); | |
data = fileInputStream.read(); | |
} | |
} | |
} | |
public void printFile2() throws IOException | |
{ | |
try (FileInputStream fileInputStream = new FileInputStream("file.txt"); | |
BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) | |
{ | |
int data = bufferedInputStream.read(); | |
while (data != -1) | |
{ | |
System.out.println(data); | |
data = bufferedInputStream.read(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment