获取文件的本地路径

时间:2015-12-03 03:17:13

标签: java path filechooser

我正在使用File Chooser选择图像以将其路径添加到数据库中 好吧,我只能得到我文件的完整路径。有没有办法从我项目的目录开始只获取本地路径?

而不是获取:C:\\Users\\Myuser\\Documents\\MyProject\\src\\Photos\\myPhoto.jpg

我希望得到类似的内容:\\src\\Photos\\myPhoto.jpg

因为我的照片所在的位置是相同的(我的src项目文件夹中的文件夹)。

我的代码:

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

0 个答案:

没有答案
相关问题