Skip to content

Instantly share code, notes, and snippets.

@kryvoboker
Created May 22, 2020 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kryvoboker/9acf1e1426d710f5291278b29db82ff4 to your computer and use it in GitHub Desktop.
Save kryvoboker/9acf1e1426d710f5291278b29db82ff4 to your computer and use it in GitHub Desktop.
HomeWork8
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author kamaz
*/
public class Main {
public static void main(String[] args) {
File file = new File("Java.txt");
try {
file.createNewFile();
} catch (IOException ex) {
System.out.println(ex);
}
String text = "";
System.out.println("Write text");
text = textForFile(text);
saveToFile(text, file);
}
public static void saveToFile(String text, File file) {
try (PrintWriter pw = new PrintWriter(file)) {
pw.println(text);
} catch (IOException e) {
System.out.println(e);
}
}
public static String textForFile(String text) {
Scanner sc = new Scanner(System.in);
text = sc.nextLine();
return text;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment