package javaapplication11;
import java.util.Scanner;
import java.io.*;
/**
*
* @author jenison-3631
*/
public class JavaApplication11 {
/**
* @param args the command line arguments
* @throws java.io.IOException
*/
public static void main(String[] args) throws IOException
{
// TODO code application logic here
// File file = new File("/Users/jenison-3631/Desktop/csvv.txt");
int n,z=1;
FileWriter writr = new FileWriter("/Users/jenison-3631/Desktop/csvv.txt");
FileReader fr= new FileReader("/Users/jenison-3631/Desktop/csvv.txt");
BufferedReader br=new BufferedReader(fr);
BufferedWriter bw= new BufferedWriter(writr);
try{
while(z==1)
{
System.out.println("please enter your choice\n1.Add number\n2.Delete number\n3.List all\n4.Search number");
Scanner s= new Scanner(System.in);
n= s.nextInt();
switch(n)
{
case 1:
String str;
String number;
System.out.println("Enter the name");
s.nextLine();
str= s.nextLine();
System.out.println("Enter the number");
number=s.nextLine();
System.out.println(str+" "+number);
/* writer.append(str);
writer.append(',');
writer.append(number);
writer.append('\n');*/
String actual=str+","+number+"\n";
bw.write(actual,0,actual.length());
break;
case 2:
String del=null;
String line=null;
String spl=",";
System.out.println("Enter the name whose phone number should be deleted");
s.nextLine();
del=s.nextLine();
while((line=br.readLine())!=null)
{
String[] country = line.split(spl);
System.out.println("hai"+country[0]);
}
System.out.println(del);
break;
}
System.out.println("Do u wish to continue....if yes press 1 else press 2");
z= s.nextInt();
}
}
finally{
bw.close();
br.close();
}
}
}
in my case 2 when I try to bring back the name from the file csvv.txt it is not working because the file is actually without data. But when I run the case 1 alone the data is writtern in the file