Created
March 7, 2016 14:56
-
-
Save sadedv/e35951728af58da91e3a to your computer and use it in GitHub Desktop.
Дописываем в файл и читаем из файла запись
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
private static void write() throws FileNotFoundException, UnsupportedEncodingException { | |
PrintWriter printWriter = new PrintWriter(new OutputStreamWriter( | |
new FileOutputStream(file, true), "UTF-8")); | |
Scanner scanner = new Scanner(System.in); | |
String line; | |
while (true) { | |
line = scanner.nextLine(); | |
if ("--stop".equals(line)) break; | |
printWriter.println(line); | |
} | |
printWriter.close(); | |
} | |
private static void read() throws IOException { | |
BufferedReader reader = new BufferedReader(new FileReader(file)); | |
String line; | |
while ((line = reader.readLine()) != null){ | |
String[] arr = line.split(" "); | |
String firstName = arr[0]; | |
String secondName = arr[1]; | |
String age = arr[2]; | |
} | |
reader.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment