Skip to content

Instantly share code, notes, and snippets.

@sadedv
Created March 7, 2016 14:56
Show Gist options
  • Save sadedv/e35951728af58da91e3a to your computer and use it in GitHub Desktop.
Save sadedv/e35951728af58da91e3a to your computer and use it in GitHub Desktop.
Дописываем в файл и читаем из файла запись
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