-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfile2.java
More file actions
28 lines (24 loc) · 829 Bytes
/
file2.java
File metadata and controls
28 lines (24 loc) · 829 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
import java.io.IOException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.Console;
import java.util.Scanner;
class file2{
public static void main(String[]args){
String filepath="output.txt";
try( BufferedWriter writer= new BufferedWriter(new FileWriter(filepath));
Scanner sc = new Scanner(System.in)){
System.out.println("Type your sentences. Enter 'q' to end:");
while(true){
String input=sc.nextLine();
if("q".equals(input)){
break;
}
writer.write(input);
writer.newLine();
}
}catch(IOException e){
System.out.println(e.getMessage());
}
}
}