1

私はファイルを読んでいます。問題は、自分のディレクトリとサブディレクトリのすべてを読み取ることができることですが、使用する.getPath()と、ルートからのフルパスが得られますC:\Users\smandre\Documents\file.txt。このパスを使用してプログラムからファイルを読み込むにはどうすればよいですか? `.getCanonicalPath() も試しました

int returnVal = c.showOpenDialog(c);

        if(returnVal == JFileChooser.APPROVE_OPTION) {
            setFilePath(c.getSelectedFile().getPath());
                try {
                br = new BufferedReader(new FileReader(getFilePath()));
            } catch (FileNotFoundException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            System.out.println("You chose to open this file: " + c.getSelectedFile().getPath());

            // System.out.println(ClassLoader.getSystemResourceAsStream(getFilePath()));
            return;
        }

明らかに、上記は現在のディレクトリからではなく、システムルートから始まるファイルパスを開こうとしています...

4

0 に答える 0