Forums Register Login

how to put contents into a file object

+Pie Number of slices to send: Send
hi
I have a question regarding file object. I have a function which is passing me string as byte array. Now when I get this string, I have to create a file with some dynamic naming, put the string content to this file and pass this file object to another function without actually creating that file physically. Is it possible ? Sorry if it seems a dumb question...

Thanks
+Pie Number of slices to send: Send
A File object does not contain any data - actual files do. You can create files from File objects via FileOutputStreams, and those will create actual files.

What do you mean by "... put content to a file ... without actually creating that file"? Either you want to store data in a file, or you don't. What's the objective here?
+Pie Number of slices to send: Send
 

s ravi chandran wrote:.. without actually creating that file physically. Is it possible ?


No. Like Tim already explained, you need to have a physical file which can store the data.
What are you trying to achieve here? If you are concerned with files lying around after you are done with them, you can always create a temp file, or write code which will delete the file explicitly.

If you can tell us why you want to avoid creating a file, we can help you better.
+Pie Number of slices to send: Send
Thanks for the reply.
Well, the code will be running on server. so, my only issue is with the file being kept at a place where its not required. The files are supposed to be passed from the application on one server to another application over another server, doing some other processing.. Also, the files are to be kept securely, and writing files will create a data leakage, which is not good from project point of view..
+Pie Number of slices to send: Send
That all sounds quite sensible. Except for the part where the decision was made to use files, which seems to conflict with the stated requirements. Clearly files which can't be written to a disk are useless. So the decision-makers need to back up a step and reevaluate the implementation strategy. Something other than files will have to be chosen.
+Pie Number of slices to send: Send
Thanks for replying.
See, its not like the files wont ever be written on any disk.. It will eventually be written on some location. The files are being used in current implementation, and I dont have any freedom to change that.. I have my application which is sort of intermediate part between the other modules..

I will be getting the contents of the files, I am creating the files names, now I have to pass it as a file object to the other module. what it does it not my concern. but creation of file from content and passing it over is what i want to do.

writing it will not be a very good idea due to many reasons, one being the security and other being the storage issue.. many other restrictions are there, but these are the main concerns...
and as there will be data coming continuously, writing of files is not looking optimal to me.
+Pie Number of slices to send: Send
 

s ravi chandran wrote:I will be getting the contents of the files, I am creating the files names, now I have to pass it as a file object to the other module. what it does it not my concern. but creation of file from content and passing it over is what i want to do.



Okay, fine. So do that. Create the file and write the data to it. That will result in there being a file on a disk somewhere. Then pass the name of the file over to the other application, which will read the file and presumably delete it.

Sure, you may think that's a security fault. And perhaps it is. But it isn't within your power to do anything about that, it appears. You have been told to use files. So there you are. Use the files, then.
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1039 times.
Similar Threads
Substring Exception
Open a file in a jsp page
concat method creates an extra String Object
creating array at run time
Do I have to have log function?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 10:02:04.