Error creating new CSV + Javafx + Windows file

Asked

Viewed 23 times

3

Good morning, everyone. I have a java desktop (javafx) application that saves some configuration data in a CSV file. The jar of the same works perfectly in both OSX and Linux, but not in Windows, I believe that I am incorrectly parametrizing the directory, but I do not remember any other way and I did not find (it is about 8 years old that I did not put my hand in Windows).

Below is the code of the passage:

Path ARQUIVO_SAIDA = Paths.get("dados.csv");
    private void salvaDados() {
    StringBuffer sb = new StringBuffer();
    for (Configuracao c : contas) {
        String linha = criaLinha(c);
        sb.append(linha);
        sb.append(System.getProperty("line.separator"));
    }
    try {
        Files.delete(ARQUIVO_SAIDA);
        Files.write(ARQUIVO_SAIDA, sb.toString().getBytes());
    } catch (IOException e) {
        e.printStackTrace();
        System.exit(0);
    }
}

also tried using the following path(in the above case the file is in the same directory as the jar)

private static final Path ARQUIVO_SAIDA = Paths.get("C:\\PastaSistema\\dados.csv");

And returns the following error:

java.nio.file.Accessdeniedexception: .csv data at sun.nio.Fs.WindowsException.translateToIOException(Unknown Source) at sun.nio.Fs.WindowsException.rethrowAsIOException(Unknown Source) at sun.nio.Fs.WindowsException.rethrowAsIOException(Unknown Source) at sun.nio.Fs.WindowsFileSystemProvider.newByteChannel(Unknown Source) at java.nio.file.spi.Filesystemprovider.newOutputStream(Unknown Source) at java.nio.file.Files.newOutputStream(Unknown Source) at java.nio.file.Files.write(Unknown Source) at br.com.denisg.integradorifood.impl.ConfigurationServiceImpl.salvaDados (Configuracaoserviceimpl.java:81) at br.com.denisg.integradorifood.impl.ConfigurationServiceImple( Configuracaoserviceimpl.java:51) at br.com.denisg.integradorifood.controller.ConfigurationController. Izar(Configuracaocontroller.java:67) at sun.reflect.Nativemethodaccessorimpl.invoke0(Native Method) at sun.reflect.Nativemethodaccessorimpl.invoke(Unknown Source) at sun.reflect.Delegatingmethodaccessorimpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.Misc.Trampoline.invoke(Unknown Source) at sun.reflect.Generatedmethodaccessor1.invoke(Unknown Source) at sun.reflect.Delegatingmethodaccessorimpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at sun.reflect.Misc.MethodUtil.invoke(Unknown Source) javafx.fxml.Fxmlloader$Methodhandler.invoke(Fxmlloader.java:1771) javafx.fxml.Fxmlloader$Controllermethodeventhandler.Handle(Fxmlloader . java:1657) at com.sun.javafx.event.Compositeeventhandler.dispatchBubblingEvent(Comp theEventHandler.java:86) at com.sun.javafx.event.Eventhandlermanager.dispatchBubblingEvent(Eventh andlerManager.java:238) at com.sun.javafx.event.Eventhandlermanager.dispatchBubblingEvent(Eventh andlerManager.java:191) at com.sun.javafx.event.Compositeeventdispatcher.dispatchBubblingEvent(C ompositeEventDispatcher.java:59) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:58) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:56) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:56) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Eventutil.fireEventImpl(Eventutil.java:74) at com.sun.javafx.event.Eventutil.fireEvent(Eventutil.java:49) javafx.event.Event.fireEvent(Event.java:198) javafx.scene.Node.fireEvent(Node.java:8411) at javafx.scene.control.Button.fire(Button.java:185) at com.sun.javafx.scene.control.behavior.Buttonbehavior.mouseReleased(Bu ttonBehavior.java:182) at com.sun.javafx.scene.control.skin.Behaviorskinbase$1.Handle(Behaviors kinBase.java:96) at com.sun.javafx.scene.control.skin.Behaviorskinbase$1.Handle(Behaviors kinBase.java:89) at com.sun.javafx.event.Compositeeventhandler$Normaleventhandlerrecord. h andleBubblingEvent(Compositeeventhandler.java:218) at com.sun.javafx.event.Compositeeventhandler.dispatchBubblingEvent(Comp theEventHandler.java:80) at com.sun.javafx.event.Eventhandlermanager.dispatchBubblingEvent(Eventh andlerManager.java:238) at com.sun.javafx.event.Eventhandlermanager.dispatchBubblingEvent(Eventh andlerManager.java:191) at com.sun.javafx.event.Compositeeventdispatcher.dispatchBubblingEvent(C ompositeEventDispatcher.java:59) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:58) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:56) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Basiceventdispatcher.dispatchEvent(Basiceventdis Patcher.java:56) at com.sun.javafx.event.Eventdispatchchainimpl.dispatchEvent(Eventdispat chChainImpl.java:114) at com.sun.javafx.event.Eventutil.fireEventImpl(Eventutil.java:74) at com.sun.javafx.event.Eventutil.fireEvent(Eventutil.java:54) javafx.event.Event.fireEvent(Event.java:198) javafx.scene.Scene$Mousehandler.process(Scene.java:3757) at javafx.scene.Scene$Mousehandler.access$1500(Scene.java:3485) javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762) at javafx.scene.Scene$Scenepeerlistener.mouseEvent(Scene.java:2494) at com.sun.javafx.tk.quantum.Glassvieweventhandler$Mouseeventnotificatio n. run(Glassvieweventhandler.java:394) at com.sun.javafx.tk.quantum.Glassvieweventhandler$Mouseeventnotificatio n. run(Glassvieweventhandler.java:295) at java.security.Accesscontroller.doPrivileged(Native Method) at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEve nt$353(Glassvieweventhandler.java:432) at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Quantum Toolkit.java:389) at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(Glas sViewEventHandler.java:431) at com.sun.Glass.ui.View.handleMouseEvent(View.java:555) at com.sun.Glass.ui.View.notifyMouse(View.java:937) at com.sun.Glass.ui.win.WinApplication. _runLoop(Native Method) at com.sun.Glass.ui.win.WinApplication.lambda$null$147(Winapplication.ja va:177) at java.lang.Thread.run(Unknown Source)

I have already given permissions in the folders even with the users All and full permission. I think it’s a really stupid mistake.

Vlww guys

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.