Write to a file stream returned from getResourceAsStream()

后端 未结 2 1279
慢半拍i
慢半拍i 2020-12-01 18:08

I am getting a a InputStream from getResourceAsStream(), and I managed to read from the file by passing the returned InputStream to a

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-01 18:34

    Is there any way I can write to the file as well?

    Who says it's a file? The whole point of getResourceAsStream() is to abstract that away because it might well not be true. Specifically, the resource may be situated in a JAR file, may be read from a HTTP server, or really anything that the implementer of the ClassLoader could imagine.

    You really shouldn't want to write to a resource that's part of your program distribution. It's conceptually the wrong thing to do in most cases. Settings or User-specific data should go to the Preferences API or the user's home directory.

提交回复
热议问题