-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPrintwritter.java
35 lines (32 loc) · 929 Bytes
/
Printwritter.java
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
import java.io.*;
import java.io.PrintWriter;
import java.util.Scanner;
public class Printwritter {
public static void main(String[] args) throws IOException {
int to = 0;
PrintWriter w = new PrintWriter("NumberList.txt");
for(int i = 1;i < 101;i++){
w.println(i);
}
w.close();
FileWriter l = new FileWriter("NumberList.txt",true);
PrintWriter p = new PrintWriter(l);
for(int i = 101;i < 201;i++){
p.println(i);
}
l.close();
File f = new File("NumberList.txt");
if(!f.exists()){
System.out.println("this file is not exist yet!");
System.exit(0);
}
Scanner s = new Scanner(f);
while(s.hasNext()){
int i = s.nextInt();
to += i;
System.out.println(i);
}
System.out.println(to);
s.close();
}
}