How can an app use files inside the JAR for read and write?

I need to store data into files inside .jar file and read it again.

I know that I can use Class.getResourceAsStream() method but it returns an InputStream that I can read from. But I look for a way to write.

This is not really supported. In principle, you could operate on the jar file, but there's no guarantee the new contents would be correctly loaded. Let your build tools manage the jar file -- and choose something else for persistent storage managed by your program itself. Like a file.