Skip to content

Instantly share code, notes, and snippets.

@kryvoboker
Created May 22, 2020 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kryvoboker/76a3026c2261ac8a346011defe207716 to your computer and use it in GitHub Desktop.
Save kryvoboker/76a3026c2261ac8a346011defe207716 to your computer and use it in GitHub Desktop.
HomeWork8(2)
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