My code is posted below. Let's say my username is ThisPC, if I write like this: "C:\Users\ThisPC\Desktop\Lista Produse.txt" it is working as intended, saving my file on desktop, but when I try with %USERNAME% it is not working. (Keep in mind I'm using Java) Thank you in advance for your help.
try{
File f=new File("C:\\Users\\%USERNAME%\\Desktop\\List.txt");
Formatter x;            
x=new Formatter("C:\\Users\\%USERNAME%\\Desktop\\List.txt");            
while(enALL.hasMoreElements()){                
    x.format(""+enALL.nextElement());
    x.format("\r\n");
 }
        x.close(); 
    }
    catch(FileNotFoundException e){
        JFrame frame = new JFrame();
        JOptionPane.showMessageDialog(frame, "Error.");
    }
 
    