-1

I need to get the file in my project put a value ( like hello word). But I need to create a jar after:

home 
   grafica
      indice_corrente.txt
      finestraprincipale.java

so I access to this file (indice_corrente.txt) in this way:

FinestraPrincipale.class.getClassLoader().getResource("src/grafica/indice_corrente.txt").toString();

I need to get the url so I can open this file with PritWriter in the jar and write into

This code give me nullpointer exception. Anyone can help me?

ddd
  • 11
  • 3

1 Answers1

0

Put your txt file under src/resources and then use path relative to resources. Like so:

FinestraPrincipale.class.getClassLoader()
    .getResource("/indice_corrente.txt")
    .toString();
Nestor Sokil
  • 2,162
  • 12
  • 28