forked from TestLeafPages/JavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileReading.java
More file actions
55 lines (37 loc) · 1.13 KB
/
FileReading.java
File metadata and controls
55 lines (37 loc) · 1.13 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
49
50
51
52
53
54
55
package coding;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;
public class FileReading extends BaseTestNg{
@Test(priority=1)
public void readUsingBuffer() throws IOException {
String str;
File file = new File("./capgemini.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
while ((str = br.readLine()) != null)
System.out.println(str);
br.close();
}
@Test(priority=2)
public void readUsingReader() throws IOException {
int i;
FileReader reader = new FileReader("./capgemini.txt");
while ((i=reader.read()) != -1)
System.out.print((char) i);
reader.close();
System.out.println("");
}
@Test(priority=3)
public void readUsingScanner() throws IOException {
File file = new File("./capgemini.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine())
System.out.println(sc.nextLine());
sc.close();
}
}