0

Hi,

I have a program that uses JButtons (under ActionEvent e) and the user clicks a button and it brings up the appropriate text file associated with that name. I have the files on a flash drive but every time i transfer the files to different computer and want to run the program on the computer, i need to change the file pathway. They are all loaded into my source package. Is there a way or code that I can have Java go into the source package to retrieve the files or to search for the files and set that pathway as a temporary string? If needed, i'll provide more code.

Thanks for your help!

JButton temp = (JButton) e.getSource();
File f = new File("J:\\AP Comp Sci\\Bible 2\\src\\bible2\\Books\\"
                + temp.getText() + ".txt");
        
        Desktop desktop = Desktop.getDesktop();
        try {
            desktop.open(f);
        } catch (Exception e1) {
            System.out.println("error");
    }
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by caswimmer2011
0
File f = new File(getClass().getResource("bible2/Books/" + emp.getText() + ".txt");

This would essentially be C:/...../src/bible2/Books/string.txt

Hope that helps!

0

It is showing me an error with the second word "File". It says "cannot find symbol" symbol: constructor File(java.net.URL) Location java.io.File.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.