Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to put contents into a file object  RSS feed

 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tim Moores
Saloon Keeper
Posts: 3828
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
s ravi chandran
Ranch Hand
Posts: 561
6
Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!