Last active
September 27, 2022 12:00
-
-
Save milten15/dfc1702d301aa3f8002eb65ab96b2426 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
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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ок а можно так же только с BufferedWriter плиз