Bonjour,
j'ai eu à me poser la même question. Voici comment j'ai procédé.
Sous linux,
File fl = new File("");//Fichier créé dans le repertoire du programme
String absPath = fl.getAbsolutePath();
File file = new File(absPath+File.separator+"text.txt");
Sous windows, ce code ne fonctionne pas. Je suis passé par une variable d'environnement (j'ai un programme qui transforme les jar en exe, avec la possibilité de mettre dans une variable d'environnement le répertoire d'installation du .exe). La variable d'environnement s'appelle ProgPath :
String absPath=System.getProperty("ProgPath");
File file = new File(absPath+File.separator+"text.txt");
Finalement, le code compatible Linux et Windows :
File fl = new File("") ;//pour obtenir Path Absolu sous Linux
String absPath = System.getProperty("ProgPath");//Pour Windows
if (absPath==null) //C'est Linux...
absPath = fl.getAbsolutePath();
File file = new File(absPath+File.separator+"texte.txt");