I wanted to work with the files, the program works in IntellijIdea, but when I create a .jar file it does not save the change to the file, it gives an error. Here is the code:

public void saveMarshall(Group currentGroup) { try { File file = new File(new URL(getClass().getResource("/resources/office_list.xml").toString()).getPath()); JAXBContext context = JAXBContext.newInstance(Group.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(currentGroup, file); } catch (JAXBException exception) { Logger.getLogger(Application.class.getName()). log(Level.SEVERE, "saveMarshall threw JAXBException", exception); } catch (MalformedURLException e) { e.printStackTrace(); } } 

Location of the .xml file: xml file location

Throws FileNotFoundException or this:

 янв 27, 2017 1:10:26 AM com.google.javafx.objects.Application saveMarshall SEVERE: saveMarshall threw JAXBException javax.xml.bind.JAXBException - with linked exception: [java.io.FileNotFoundException: file:\D:\IdeaProject\JavaFXInstaBot\out\artifacts\JavaFX\JavaFXWorkXMLFile.jar!\resources\office_list.xml (БинтаксичСская ошибка Π² ΠΈΠΌΠ΅Π½ΠΈ Ρ„Π°ΠΉΠ»Π°, ΠΈΠΌΠ΅Π½ΠΈ ΠΏΠ°ΠΏΠΊΠΈ ΠΈΠ»ΠΈ ΠΌΠ΅Ρ‚ΠΊΠ΅ Ρ‚ΠΎΠΌΠ°)] at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:108) at com.google.javafx.objects.Application.saveMarshall(Application.java:94) 
  • changing the file stored in the jar is not encouraged. This, of course, can be done, but through crutches, I advise you to save to the file lying next to the jar or in some other directory, but not inside the archive. - Artem Konovalov
  • @ArtemKonovalov and how to make so that no one saw this file (how to hide it)? - Nursultan Zhyenbaev
  • one
    no, next to the usual directory you create and write files there. - Artem Konovalov

1 answer 1

When creating Windows Jar, it takes a little differently the location of the files in your case, I advise you to try to make File file = new File(System.getProperty("user.dir") + "/resources/office_list.xml"); . I myself have encountered such a problem))) One more reason is possible: inside your xml file refers to an empty file

  • What does it have to do with Windows? - Pavel Mayorov