i dont think that there is way to do this since when you read from a File, you do not read via the File object but through a FileInputStream which is constructed with the File or the filepath (the File classs has no read/write methods). So you should work with InputStream which can be either a FileInputStream (from filesystem) or a ByteArrayInputSteam or a XYZInputStream.
On linux you may have virtual-filesystem support. And on dos, you could create a ramdisk too in former times - don't know about today. Of course this would make installation of your program on different machines difficult...
I liked Pascal's mention of the streams involved. I'm guessing from your requirement for a File object you are calling a method that expects a file:
Could you change the method to want an inputstream argument?
This kind of thinking comes up all the time in "test first development" where you write JUnit tests before you write the code. It's dead simple for a unittest to create an input stream froma string, just as you wanted to do, but a real hassle to create a disk file, run the test and erase the disk file.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi