Created
May 22, 2020 18:12
-
-
Save kryvoboker/9acf1e1426d710f5291278b29db82ff4 to your computer and use it in GitHub Desktop.
HomeWork8
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
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