-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileExample.java
49 lines (38 loc) · 1.06 KB
/
fileExample.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class fileExample {
public static void main(String[]args){
writeFile();
deleteFile();
}
static void writeFile(){
try{
File fs= new File("Student.txt");
// if(fs.createNewFile()){
// System.out.println("new file has been creatd");
// }else{
// System.out.println("file already exist");
// }
// FileWriter fsw= new FileWriter(fs);
// BufferedWriter fsbw= new BufferedWriter(fsw);
// fsbw.write("this is text.");
FileReader fr= new FileReader(fs);
BufferedReader bfr=new BufferedReader(fr);
String data="";
while((data=bfr.readLine())!=null){
System.out.println(data);
}
bfr.close();
}
catch(Exception e){
System.out.println(e);
}
}
static void deleteFile(){
File fs= new File("student.txt");
fs.delete();
}
}