-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputOutputTXT.java
More file actions
41 lines (35 loc) · 978 Bytes
/
InputOutputTXT.java
File metadata and controls
41 lines (35 loc) · 978 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
29
30
31
32
33
34
35
36
37
38
39
40
41
package TwoChapter1StreamFile;
import java.io.Closeable;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class InputOutputTXT implements Closeable{
/*
* 1.输出文本到文件
* 2.读文本
*
* */
public static void main(String[] args) {
//try-with-catch--语法糖
try( Scanner in=new Scanner(new FileInputStream("src\\readme.txt"));
PrintWriter out= new PrintWriter("src\\readme.txt")){
//PrintWriter out=new PrintWriter(new FileWriter("readme.txt"),true);
//是上面写法的简写,true代表自动刷新
//打印到写出器
out.println("name");
out.print("password");
out.println(100);
out.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void close() throws IOException {
// TODO Auto-generated method stub
System.out.println("关闭输入/输出流");
}
}