0

I'm using File Chooser to select an image to add it's path into database.
Well, I can only get the FULL path of my file. Is there a way to get only the local path, starting from my project's directory ?

Instead of get: C:\\Users\\Myuser\\Documents\\MyProject\\src\\Photos\\myPhoto.jpg

I'd like to get something like: \\src\\Photos\\myPhoto.jpg.

Because the place where my photo will always be is the same (A folder inside my src project folder).

My Code:

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        JFileChooser filec = new JFileChooser(".\\src\\imgs\\");
        filec.showOpenDialog(null);
        File f = filec.getSelectedFile();
        if(f != null){
            JOptionPane.showMessageDialog(null, filec.getCurrentDirectory());
        //f.getPath();
       //f.getAbsolutePath();
        }
    } 
PlayHardGoPro
  • 2,791
  • 10
  • 51
  • 90
  • Also, you must realise, that once you program is built and deployed, `src` fill no longer exists, you should NEVER have a reference to `src` in you code – MadProgrammer Dec 03 '15 at 03:22
  • @MadProgrammer So the best way to go is to keep the full path ? – PlayHardGoPro Dec 03 '15 at 03:23
  • With out the full context to your problem, you might consider have a directory within either the current working directory (`.`) or within a well known location (like `{user.home}/AppData/Local/{You application Name}` on Windows) – MadProgrammer Dec 03 '15 at 03:24

0 Answers0