ObjectInputStream happy with FileInputStream, not happy with getResourceAsStream

后端 未结 5 1752
闹比i
闹比i 2020-12-10 12:42

I have some pretty standard code which takes in a serialized object from a stream, which bascially looks like this:

  Object getObjectFromStream(InputStream is) {         


        
5条回答
  •  生来不讨喜
    2020-12-10 13:18

    There should be no difference at all -- the path you're using for getResourceAsStream() must be finding some other file. Do a search for other files stored as serializedObjects/testObject, and see if you can't find it. Remember that the FileInputStream is going to be looking relative to the current directory, while the getResourceAsStream() is relative to the class path.

提交回复
热议问题