Question
For some reason, I'm getting erorr message everytime I run the code saying that it cannot locate the csv file or Exception occured: java.io.FileNotFoundException: bank-Details.csv
For some reason, I'm getting erorr message everytime I run the code saying that it cannot locate the csv file or
Exception occured: java.io.FileNotFoundException: bank-Details.csv (No such file or directory)
I have added the csv file to the directory however it still fails to locate it , here is the code:
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class BankRecords extends Client{
FileReader fr = new FileReader("bank-Detail.csv"); // REading File bank-Details from D:\ Drive
BufferedReader br = null;
String line = "";
String cvsSplitBy = ",";
ArrayList
BankRecords bankrecords[];
BankRecords(){
}
@Override
void readData() {
try{
//br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine()) != null) {
dataList.add(line);
}
bankrecords= new BankRecords[dataList.size()];
}
catch(FileNotFoundException e){
System.out.println("Exception occured: "+e);
}
catch(Exception e){
System.out.println("Exception occured: "+e);
}finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
void processData() {
// TODO Auto-generated method stub
for(int i=0;i String data[] = dataList.get(i).split(","); bankrecords[i] = new BankRecords(); bankrecords[i].setId(data[0]); bankrecords[i].setAge(Integer.parseInt(data[1])); bankrecords[i].setSex(data[2]); if(data[3].equals("TOWN") || data[3].equals("RURAL") ) bankrecords[i].setRegion(data[3]+" ");// for proper formatting of the output i have added these extra spaces else bankrecords[i].setRegion(data[3]); bankrecords[i].setIncome(Float.parseFloat(data[4])); if("YES".equals(data[5]) || "yes".equals(data[5])) bankrecords[i].setMarried(true); else bankrecords[i].setMarried(false); bankrecords[i].setChildern(Integer.parseInt(data[6])); if("YES".equals(data[7]) || "yes".equals(data[7])) bankrecords[i].setHasCar(true); else bankrecords[i].setHasCar(false); if("YES".equals(data[8]) || "yes".equals(data[8])) bankrecords[i].setHasSav_act(true); else bankrecords[i].setHasSav_act(false); if("YES".equals(data[9]) || "yes".equals(data[9])) bankrecords[i].setHasCur_act(true); else bankrecords[i].setHasCur_act(true); if("YES".equals(data[10]) || "yes".equals(data[10])) bankrecords[i].setMortgage(true); else bankrecords[i].setMortgage(false); if("YES".equals(data[10]) || "yes".equals(data[10])) bankrecords[i].setPep(true); else bankrecords[i].setPep(false); } } @Override void PrintData() { // TODO Auto-generated method stub //System.out.printf("%-20s%-11s%-18s%-16s%-12s%-26s%-12s ","S.no","ID","AGE","SEX","REGION","INCOME","MORTGAGE"); System.out.println("S.no \t\t"+" ID \t\t"+"AGE \t\t"+ "SEX \t\t"+"REGION \t\t\t"+ "INCOME \t\t" +"MORTGAGE \t\t"); for(int i=0;i<25;i++){ System.out.println( (i+1)+"\t\t"+bankrecords[i].getId()+"\t\t"+bankrecords[i].getAge()+"\t\t"+bankrecords[i].getSex()+"\t\t"+bankrecords[i].getRegion()+"\t\t"+bankrecords[i].getIncome()+"\t\t"+bankrecords[i].isMortgage()); } } public static void main(String args[]){ BankRecords bankrecord = new BankRecords(); bankrecord.readData(); bankrecord.processData(); bankrecord.PrintData(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started