-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabcd.java
More file actions
49 lines (45 loc) · 1.51 KB
/
abcd.java
File metadata and controls
49 lines (45 loc) · 1.51 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
import java.io.*;
import java.util.ArrayList;
public class abcd{
static ArrayList<String[]> records =new ArrayList<>();
public static void main(String[] args) {
// String path;
// path="C:\\Users\\Muringo\\Desktop\\assignment\\test1.txt";
// String message;
// message="\n\nhello again";
// writeFile(path, message);
readCSV();
System.out.println(records);
}
static void writeFile(String path, String message){
try{
File file= new File(path);
FileWriter fileInput= new FileWriter(file,true);
fileInput.write(message);
fileInput.close();
}catch(FileNotFoundException e){
System.out.println(e.getMessage());
}catch(IOException e){
System.out.println(e.getMessage());
}catch(Exception e){
System.out.println(e.getMessage());
}
}
static void readCSV() {
String pathCSV;
pathCSV="C:\\Users\\\\Muringo\\Desktop\\assignment\\test2.csv";
File file= new File(pathCSV);
try(FileReader reader= new FileReader(file)){
BufferedReader br = new BufferedReader(reader);
String line;
while((line=br.readLine())!=null){
records.add(line.split(","));
}
}catch(FileNotFoundException e){
System.out.println(e.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}