-
Notifications
You must be signed in to change notification settings - Fork 2
/
WriteToFile.java
31 lines (22 loc) · 915 Bytes
/
WriteToFile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import javax.swing.*;
import java.io.*;
public class WriteToFile
{
public static void main(String [] args){
String input = JOptionPane.showInputDialog("input here to write to text file");
try{
File myFile = new File("D:/Galario/myFile.txt"); // creation of file
if(!myFile.exists()){
myFile.createNewFile();
}
FileWriter fw = new FileWriter(myFile,true); // check if the file is ready for writing
BufferedWriter hbw = new BufferedWriter(fw); // our writer
hbw.write("INPUT: " + input); // write into the file
hbw.newLine(); // nextLine
hbw.close();
System.out.println("Success!");
}catch( IOException e){
System.out.println("Exception Occured!");
}
}
}