Create a File object in memory from a string in Java

后端 未结 5 1236
独厮守ぢ
独厮守ぢ 2020-12-08 12:59

I have a function that accepts File as an argument. I don\'t want to create/write a new File (I don\'t have write access to filesystem) in order to pass my string data to th

5条回答
  •  借酒劲吻你
    2020-12-08 13:49

    The File class represents the "idea" of a file, not an actual handle to use for I/O. This is why the File class has a .exists() method, to tell you if the file exists or not. (How can you have a File object that doesn't exist?)

    By contrast, constructing a new FileInputStream(new File("/my/file")) gives you an actual stream to read bytes from.

提交回复
热议问题