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();
}
}