-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintStreamTest.java
More file actions
50 lines (42 loc) · 1.31 KB
/
Copy pathPrintStreamTest.java
File metadata and controls
50 lines (42 loc) · 1.31 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
package tutorial.java;
import java.io.*;
/* This small project can be used when user wants to save what they type in
(using BufferedReader.readLine()) to a local file.
* */
public class PrintStreamTest {
// @Test
// public void test(){
public static void main(String[] args) {
System.out.println("please insert your data");
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(new File("/Users/Alexpower/Desktop/test.txt"));
ps = new PrintStream(fos, true);
if(ps != null){
System.setOut(ps);
}
// for(int i= 0; i <= 255; i++){
// System.out.println((char) i);
// if(i % 50 == 0){
// System.out.println();
// }
// }
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
while (true){
String data = br.readLine();
System.out.println(data);
if("e".equalsIgnoreCase(data) || "exit".equalsIgnoreCase(data)){
System.out.println("program exit");
break;
}
}
}catch (IOException e){
e.printStackTrace();
}finally {
if(ps != null){
ps.close();
}
}
}
}