Sample csv
file datas
person.csv
name,address,city,state,country
daniel,zzzzzzzz,xxxxxxxx,TN,India
peter,xxxxxxxx,yyyyyyyy,TN,
India
john,rrrrrrrr,
gggggggg,TN, India
andrew,xxxxxxxx,
zzzzzzzz,TN, India
mark,hhhhhhhh,
qqqqqqqq,TN, India
mathew,kkkkkkkk, yyyyyyyy,TN, India
Person.java
public class
Person
{
private String name;
private String address;
private String city;
private String state;
private String country;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
}
SearchData.java
import
java.io.BufferedReader;
import
java.io.FileNotFoundException;
import
java.io.FileReader;
import
java.io.IOException;
import
java.io.InputStreamReader;
import
java.util.ArrayList;
import
java.util.List;
public class
SearchData
{
public static void main(String args[])
throws FileNotFoundException, IOException
{
BufferedReader br=new BufferedReader(new
FileReader("person.csv"));
BufferedReader buf=new
BufferedReader(new InputStreamReader(System.in));
String input;
String line;
List<Person>pn=new ArrayList<Person>();
while((line=br.readLine())!=null)
{
String[]data=line.split(",");
Person person=new Person();
person.setName(data[0]);
person.setAddress(data[1]);
person.setCity(data[2]);
person.setState(data[3]);
person.setCountry(data[4]);
pn.add(person);
}
System.out.println("Enter the
name");
input=buf.readLine();
for(int i=1;i<pn.size();i++)
{
if(input.contains(pn.get(i).getName()))
{
System.out.println("Name
\tAddress \tCity \t\tState \t\tCountry");
System.out.println(pn.get(i).getName()+"\t"+pn.get(i).getAddress()+"\t\t"+pn.get(i).getCity()+"\t\t"+pn.get(i).getState()+"\t\t"+pn.get(i).getCountry());
}
}
}
}
output:
Enter the
name
peter
Name Address City
State Country
peter xxxxxxx yyyyyyyy TN India
No comments:
Post a Comment