-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIOTest.java
More file actions
51 lines (46 loc) · 1.37 KB
/
IOTest.java
File metadata and controls
51 lines (46 loc) · 1.37 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package FileReader;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.*;
import java.util.Scanner;
/**
* @author nicholaszetzl
*/
public class IOTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
File file = new File("Text");
FileOutputStream fos = new FileOutputStream(file, true);
PrintWriter pw = new PrintWriter(fos);
Scanner s = new Scanner(System.in);
System.out.println("Enter input to be placed into a file. When you are done type '^]' and press enter.");
while (true) {
String line = s.nextLine();
if (line.equals("^]")) {
break;
} else {
pw.println(line);
}
}
s.close();
pw.close();
FileReader fr = new FileReader(file);
BufferedReader bfr = new BufferedReader(fr);
String st;
System.out.println("This is the text of the file:");
while (true) {
st = bfr.readLine();
if (st == null) {
break;
} else {
System.out.println(st);
}
}
bfr.close();
}
}