File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Creation of File object on the fly.... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Mongo DB Applied Patterns this week in the MongoDB forum
or a resume review from Five Year Itch in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Creation of File object on the fly...." Watch "Creation of File object on the fly...." New topic
Author

Creation of File object on the fly....

Gurumurthy Ramamurthy
Ranch Hand

Joined: Feb 13, 2003
Posts: 272
Hi all,

I have a string using which I need to create a file object and I don't want to store to the hard-disk.

Is there anyway to create File object from reading the contents from buffer.

Say, for example: I have the string:
String s="hello, this is the contents of the file". I need to create the File object for this contents and I don't want to store/retrive to/from hard-disk.

Thanks,
Guru
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
hi

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.


cheers

pascal
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
File is just a handle to a physical file or directory on disk, it's not equipped to handle memory-mapped files.


42
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

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...


http://home.arcor.de/hirnstrom/bewerbung
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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 unit test 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creation of File object on the fly....
 
Similar Threads
searching a large list of words
Read .dsp file
Why iPod requires internet access ?
Struts 1.3 file handling mechanism - help
File based persistent store with Java