Skip to content

Instantly share code, notes, and snippets.

@milten15
Last active September 27, 2022 12:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milten15/dfc1702d301aa3f8002eb65ab96b2426 to your computer and use it in GitHub Desktop.
Save milten15/dfc1702d301aa3f8002eb65ab96b2426 to your computer and use it in GitHub Desktop.
package com.javarush.test.level13.lesson11.home04;
/* Запись в файл
1. Прочесть с консоли имя файла.
2. Считывать строки с консоли, пока пользователь не введет строку "exit".
3. Вывести абсолютно все введенные строки в файл, каждую строчку с новой стороки.
*/
import java.io.*;
public class Solution
{
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
OutputStream outputStream = new FileOutputStream(reader.readLine());
while (true)
{
String data = reader.readLine();
if(data.equals("exit")){
outputStream.write(data.getBytes());
break;
}
else {
outputStream.write((data +"\r\n").getBytes());
}
}
outputStream.close();
reader.close();
}
}
@RostStepaniuk
Copy link

ок а можно так же только с BufferedWriter плиз

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment