0

Please find what am i missing here the output: https://drive.google.com/open?id=1Ur6XOHWJAoJ7aVLRqNP8E39j3Hz9E2T8

try
{
  FileReader fr = new FileReader ("residenceData.txt");
  BufferedReader br = new BufferedReader (fr);
  BufferedWriter bw1 = new BufferedWriter (new FileWriter ("resKelantan.txt:"));

  StringTokenizer st = null;
  String dataRow = br.readLine();
  while (dataRow != null)
  {
  st = new StringTokenizer (dataRow, "#");
  id = Integer.parseInt(st.nextToken());
  race = (st.nextToken().charAt(0));
  numChild = Integer.parseInt(st.nextToken());
  income = Double.parseDouble(st.nextToken());
  state = st.nextToken();

   Residence r1 = new Residence (id, race, numChild, income, state);

   if (r1.getState().equalsIgnoreCase("kelantan"))
   {
     pw1.println(r1.toString());
   }

  dataRow = br.readLine();

  }
Ress
  • 1
  • 1

1 Answers1

0

You better create File first, and then use boolean function File.exists() to find put if this file exists. If so, you can use you code: try{...} and so on. If not, you may call File.createNewFile() function. For example:

File f = new File("somefile");
if (f.exists()) {
    FileReader fr = new FileReader(f);
}
Dima Rich
  • 61
  • 6