Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

.getAbsolutePath() .getCanonicalPath() System.getProperty("user.dir")

843806Jun 27 2008 — edited Jun 28 2008
Hello,
Im writing a swing application (not an online one) and I'm trying to access text files from a jar file that's not apart of the jar.
But Im having trouble accessing them.

heres apart of my code:
public static void main(String args[]) {
final SeqGUI Sequence1 = new SeqGUI();
java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Sequence1.setVisible(true);
...
String URL3 = "textdocs/contig2.txt";
                
try {
int one = 1;
seq_gene = Sequence1.fileOpener(URL0, one);
}
...
}

public ArrayList fileOpener(String inputmain, int firstline) throws FileNotFoundException {
        try {
            if (firstline == 1) {
               
              String input = new java.io.File("").getAbsolutePath();
               Textbox.append(input+"\n");
               
               input = new java.io.File("").getCanonicalPath();
               Textbox.append(input+"\n");
               
               input = System.getProperty("user.dir");
               Textbox.append(input+"\n");
               
                 URL url = this.getClass().getResource("/"+inputmain);
                if (url == null) {
                Textbox.append("  File was not found in the class path.  ");
                }
                else {
                File fileh = new File(url.getFile());
                System.out.println("I exists, somehow...");.
               }
               
               InputStream is = new FileInputStream(fileh);
               .....
 }
}
This returns:
/home/sean
/home/sean
/home/sean
File was not found in the class path. textdocs/contig2.txt
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 26 2008
Added on Jun 27 2008
5 comments
732 views