Where to place a text file for use with a Java project in Eclipse

I placed a text file myapp.txt in the folder ~/workspace/PayrollApp/src/org/username/payrollapp. However, it was not opening in the Java program.

To make it work correctly, I had to do use the following path in the Java program when opening the file:
src/org/username/payrollapp/pay.txt

Code as follows:

   try {
      FileReader fr = new FileReader("src/org/username/payrollapp/pay.txt");
      BufferedReader br = new BufferedReader(fr);
      String line = null;
      while ((line = br.readLine()) != null) {
         String[] result = line.split(":");
         result[1] = result[1].replaceAll("~~", "\n\n");
         helpText.append(result[0] + ": " + result[1] + "\n");
      }
      helpDialog.pack();
      helpDialog.setVisible(true);
   } catch (IOException ex) {
      ex.printStackTrace();
   }

Leave a Reply

  

  

  

Blue Captcha Image
Refresh

*

September 2019
M T W T F S S
« Aug    
 1
2345678
9101112131415
16171819202122
23242526272829
30