-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathep10_5.java
More file actions
33 lines (31 loc) · 1.22 KB
/
ep10_5.java
File metadata and controls
33 lines (31 loc) · 1.22 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
import java.io.*;
//通过程序创建一个文件,从键盘输入字符,当遇到字符”#“时结束,在屏幕上显示该文件的所有内容。
public class ep10_5 {
public static void main(String args[]){
char ch;
int data;
try{
FileInputStream a = new FileInputStream(FileDescriptor.in); //创建文件输入流对象
FileOutputStream b = new FileOutputStream("ep10_5"); //创建文件输出流对象
System.out.println("请输入字符,以#号结束:");
while ((ch = (char) a.read()) != '#'){
b.write(ch);
}
a.close();
b.close();
System.out.println();
FileInputStream c = new FileInputStream("ep10_5");
FileOutputStream d = new FileOutputStream(FileDescriptor.out);
while (c.available() > 0){
data = c.read();
d.write(data);
}
c.close();
d.close();
}catch (FileNotFoundException e){
System.out.println("找不到该文件!");
}catch (IOException io){
System.out.println("IOException:" + io);
}
}
}