Create a File object in memory from a string in Java

后端 未结 5 1244
独厮守ぢ
独厮守ぢ 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:43

    FileReader r = new FileReader(file);
    

    Use a file reader load the file and then write its contents to a string buffer.

    example

    The link above shows you an example of how to accomplish this. As other post to this answer say to load a file into memory you do not need write access as long as you do not plan on making changes to the actual file.

提交回复
热议问题