Created
May 22, 2020 19:31
-
-
Save kryvoboker/76a3026c2261ac8a346011defe207716 to your computer and use it in GitHub Desktop.
HomeWork8(2)
This file contains 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
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileReader; | |
import java.io.IOException; | |
/** | |
* | |
* @author kamaz | |
*/ | |
public class Main { | |
public static void main(String[] args) { | |
File file = new File("Massiv.txt"); | |
String text = readFile(file); | |
System.out.println(text); | |
} | |
public static String readFile(File file) { | |
StringBuilder sb = new StringBuilder(); | |
try (BufferedReader br = new BufferedReader(new FileReader(file))) { | |
String text = ""; | |
for (; (text = br.readLine()) != null;) { | |
sb.append(text); | |
sb.append(System.lineSeparator()); | |
} | |
} catch (IOException e) { | |
System.out.println(e); | |
} | |
return sb.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment