-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFile.java
More file actions
33 lines (30 loc) · 747 Bytes
/
WriteFile.java
File metadata and controls
33 lines (30 loc) · 747 Bytes
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
32
33
package algorithms;
import java.io.*;
import java.util.Scanner;
/**
*
* @author Gökhan DAĞTEKİN
*
* 2015
*/
public class WriteFile {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a sentence: ");
String sentence = sc.nextLine();
File f = new File("text.txt");
PrintWriter p = null;
try {
p = new PrintWriter(new FileOutputStream(f, true)/*f*/);
if (!f.exists()) {
f.createNewFile();
}
p.println(sentence);
p.close();
} catch (Exception e) {
System.out.println("Error");
} finally {
p.close();
}
}
}