-1

I have a file loaded in memory, through the RandomAccessFile (in java).

Do not put it in the disc because it is a temporary file, and it is very important not to be stored for their safety.

Is it possible RandomAccessFile open with the default application of the system?, I can not find an alternative that convinces me. I know there are "temporary files" but I do not generate a lot of security.

user60108
  • 3,270
  • 2
  • 27
  • 43
  • Are you sure this is a security concern? The default associated program will likely buffer your bytes to a temporary file on disk *anyway*, or autosave it, or the user may save the file manually. If it's critical that the data aren't saved to disk, then you can't trust an arbitrary external program with them. – Andrzej Doyle Mar 07 '13 at 17:28
  • @Andrzej Doyle The option to open the file with an external program is a user desicion. Instead the disk storing is mine. – user60108 Mar 07 '13 at 17:36
  • Choosing to open the file in another application is essentially choosing to store to disk. If they click "Open With External Program" write the data to a temporary file. – dimo414 Mar 07 '13 at 20:20
  • 2
    I do not understand. RandomAccessFile can only read and write from and to a disk. The question doesn't begin to make sense. – user207421 Mar 07 '13 at 23:21

2 Answers2

1

You can use Desktop.open() to open a file by file name with it's associated program. Before you do this, you should close any resources using it in Java.

How you created the file doesn't matter.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • yes. And that's what I like to do! but the problem is that I not have a file, I have a RandomAccessFile – user60108 Mar 07 '13 at 18:01
  • You have to know the path to re-open it. How was the RandomAccessFile created in the first place? – Peter Lawrey Mar 07 '13 at 18:07
  • It's a bit complex. But in the end what you have are the bytes of what was once a file. The original file from which they were copied those bytes could be removed. – user60108 Mar 07 '13 at 18:16
  • In that case you can copy the file content to a file name you know. e.g. using `File.createTempFile()` The problem is you have to know what extension to give the file as this is used to open the right program. – Peter Lawrey Mar 07 '13 at 18:17
  • know the file extension is not a problem, the problem of using tempFile is not generating a lot of security. They are sensitive Files that no unauthorized person can not know. – user60108 Mar 07 '13 at 18:27
  • You can't re-open a file in another program without it's name. If the access has to be secure, could the temporary file be under the user's home directory, in a directory only they have access to? – Peter Lawrey Mar 07 '13 at 18:30
  • I do not know ..., creating files with sensitive information does not generate a lot of security. – user60108 Mar 07 '13 at 18:36
  • I don't understand what you mean. A file in a directory which can only be accessed by one user, can only be accessed by one user. If you can't trust the security of your filesystem there is nothing you can do but use another OS. – Peter Lawrey Mar 07 '13 at 18:39
  • I prefer to give the option "export" to the user before opening with the default application. Imagine you are a user and contains valuable information, you open a file with the default application of the system and then find the file in your home, would you generate security? – user60108 Mar 07 '13 at 18:50
  • 1
    I don't know what you mean by "generate security". Why would a user be concerned seeing one of their files under their home directory? Where would they expect them to go instead? – Peter Lawrey Mar 08 '13 at 11:18
0

Perhaps you could share some code describing how you're creating this RandomAccessFile? The constructors for this class expect either a File object or the path to a file. It should be possible to open any File object with the associated default application.

If as you say the RandomAccessFile class is actually reading from memory and not a file, then you may be out of luck - most programs expect to open files, not memory addresses.

Community
  • 1
  • 1
dimo414
  • 47,227
  • 18
  • 148
  • 244
  • RandomAccessFile was generated manually writing all bytes – user60108 Mar 07 '13 at 17:37
  • 1
    That's fine, but you still had to specify a path in order to construct the RAF in the first place. Again, posting a code example will help us help you. – dimo414 Mar 07 '13 at 20:18