-
-
Save mariiaKolokolova/69616ae128221a44913c0acc02b8c233 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 maricka.kolokolova; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
File file = new File("b.txt"); | |
try { | |
file.createNewFile(); | |
} catch (IOException e) { | |
System.out.println(e); | |
} | |
Scanner sc = new Scanner(System.in); | |
System.out.println("Input your text:"); | |
StringBuilder br = new StringBuilder(); | |
String text; | |
for (;;) { | |
text = sc.nextLine(); | |
if (text.equals(":exit")) { | |
break; | |
} | |
br.append(text); | |
br.append(System.lineSeparator()); | |
} | |
saveToFile(br.toString(), file); | |
sc.close(); | |
} | |
public static void saveToFile(String text, File file) { | |
try (PrintWriter pr = new PrintWriter(file)) { | |
pr.print((text)); | |
} catch (FileNotFoundException e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Saved!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment