jeudi 5 novembre 2015

Can't use URL for File

My old version works, but if I try to export to runnable Jar File, it doesn't load the txt file.

public String jarLocation = getClass().getProtectionDomain()
        .getCodeSource().getLocation().getPath();
public File txt = new File(jarLocation + "/images/gewinne.txt");

After that I tried with get Resource, but the File can't load the URL part :/ I am lost

public URL urlGewinne = Kalender.class.getResource("/images/gewinne.txt");
public File txt = new File(urlGewinne); // ERROR

public void txtLesen() throws IOException {
    try {
        BufferedReader br = new BufferedReader(new FileReader(txt));
        String line = null;
        while ((line = br.readLine()) != null) {
            gewinne.add(line);
        }

        br.close();
    } catch (FileNotFoundException ex) {

    }
}

Aucun commentaire:

Enregistrer un commentaire