-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstream1.java
More file actions
49 lines (40 loc) · 1.15 KB
/
Copy pathstream1.java
File metadata and controls
49 lines (40 loc) · 1.15 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
//learn from: http://www.runoob.com/java/java-files-io.html
1. 控制台输入字符
import java.io.*;
public class BBREAD {
public static void main(String args[]) throws IOException
{
char c;
// 使用 System.in 创建 BufferedReader
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter characters, 'q' to quit.");
// 读取字符
do {
c = (char) br.read();
System.out.println(c);
} while(c != 'q');
}
}
----
Enter characters, 'q' to quit.
2. 控制台输入字符串
import java.io.*;
public class BBREAD {
public static void main(String args[]) throws IOException
{
// 使用 System.in 创建 BufferedReader
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
String str;
System.out.println("Enter lines of text.");
System.out.println("Enter 'end' to quit.");
do {
str = br.readLine();
System.out.println(str);
} while(!str.equals("end"));
}
}
---
Enter lines of text.
Enter 'end' to quit.