Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Open a file on the fly

 
Marco Lombardo
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there way to open a file without save it in file system?
For example:
I have a byte[] object or java.io.File (or Stream) and i want to
open a file without save it.

Can i use Runtime.getRuntime().exec(....) to open a file
not in file system?
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean by "open a file without saving it?". A file cannot be opened unless it exists on disk.

Perhaps you are thinking of the way you can open a new document in, say, Microsoft Word, without saving it. That's something completely different. You could implement such a user interface in Java, but that has little to do with Java File objects.

You can create a Java File object for a file that does not exist. A Java File object is just an abstract pathname. However, creating a Java File object does not mean you have "opened" the file. To open the file, you need a RandomAccessFile, an InputStream, an OutputStream or an NIO channel (I'm a bit hazy on them). For any of those, the file must already exist or will be created as part of the opening process.
[ July 17, 2006: Message edited by: Peter Chase ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please don't post the same question to multiple forums; I deleted the other copy you posted in IO and Streams because this one already has a discussion.

I also can't really understand what you're asking, but does java.io.ByteArrayInputStream help you?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic