java - The filename, directory name or volume label syntax is incorrect - Kotlin - Maven -


i error when start packaged jar. when run ide not give error , run.

java.io.filenotfoundexception: file:\c:\development\kotlin\accounttool\target\accounttool-1.0-snapshot-jar-with-dependencies.jar!\accounts.json (the filename, directory name or volume label syntax incorrect)     @ java.io.fileinputstream.open0(native method)     @ java.io.fileinputstream.open(unknown source)     @ java.io.fileinputstream.<init>(unknown source)     @ java.io.fileinputstream.<init>(unknown source)     @ java.io.filereader.<init>(unknown source)     @ com.martacus.accounttool.toolview$handler.readdata(tool.kt:41)     @ com.martacus.accounttool.toolview.<init>(tool.kt:56)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance0(native method)     @ sun.reflect.nativeconstructoraccessorimpl.newinstance(unknown source)     @ sun.reflect.delegatingconstructoraccessorimpl.newinstance(unknown source)     @ java.lang.reflect.constructor.newinstance(unknown source)     @ java.lang.class.newinstance(unknown source)     @ tornadofx.fxkt.find(fx.kt:238)     @ tornadofx.app.start(app.kt:27)     @ com.sun.javafx.application.launcherimpl.lambda$launchapplication1$159(unknown source)     @ com.sun.javafx.application.launcherimpl$$lambda$52/31866147.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$runandwait$172(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$45/2900468.run(unknown source)     @ com.sun.javafx.application.platformimpl.lambda$null$170(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$48/4210449.run(unknown source)     @ java.security.accesscontroller.doprivileged(native method)     @ com.sun.javafx.application.platformimpl.lambda$runlater$171(unknown source)     @ com.sun.javafx.application.platformimpl$$lambda$47/24077489.run(unknown source)     @ com.sun.glass.ui.invokelaterdispatcher$future.run(unknown source)     @ com.sun.glass.ui.win.winapplication._runloop(native method)     @ com.sun.glass.ui.win.winapplication.lambda$null$145(unknown source)     @ com.sun.glass.ui.win.winapplication$$lambda$36/1828305.run(unknown source)     @ java.lang.thread.run(unknown source) 

code , file hierarchy in ide: enter image description here

fun readdata(){     accounts.clear()     var readfile = toolview::class.java.classloader.getresource("accounts.json").file     println(readfile)     filereader(readfile).use{         var account = gson.fromjson(it, array<account>::class.java) ?: return         for(i in account){             accounts.add(i)         }     }  } 

.jar root:

enter image description here

i have no idea going wrong , why giving me error. searching on stackoverflow , google didnt provide me right answer. hope here can me, if need more info please so.

thanks!

when resource packed jar, not available file in filesystem anymore. therefore cannot use standard api working filesystem file() or filereader() access contents of resource.

instead should open resource stream class.getresourceasstream or classloader.getresourceasstream methods , read content stream:

val stream = toolview::class.java.classloader.getresourceasstream("accounts.json")  stream.reader().use {     println(it.readtext()) } 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -