Results 1 to 9 of 9
Thread: I/O How to open a file
- 07-18-2011, 02:25 AM #1
- 07-18-2011, 02:34 AM #2
What do you mean by "open". Using the classes in the IO package you can read the contents of a file. You can then display the contents on a JTextArea. Is this what you mean? Are you trying to write your own text editor?
- 07-18-2011, 02:36 AM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,144
- Rep Power
- 5
Not sure I understand your question but I will make a guess that you are interested in: How to Integrate with the Desktop Class (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
- 07-18-2011, 02:44 AM #4
I am referring to simply opening a file. For instance, if you had a file on your desktop called results.txt, and you double click it, it opens.
Basically within my program, I am creating and writing to a text file. Once this is done, I would like to open the file so the user can see the results, without having to navigate to the file and manually open it.
- 07-18-2011, 02:50 AM #5
You keep saying "open" but it really isn't very clear what you want to do. If you mean start another application to display the file then it all depends upon what the file is. If it is a plain text file then you can open it with Notepad, Wordpad, Word or any other text editor. If this is what you really what then research using Runtime.exec and make sure you Google for the pitfalls associated with this.
- 07-18-2011, 03:10 AM #6
not sure what I'm not explaining. Just want to open it, have it be presented to the user, so they can see the text file, as if I double-clicked the .txt file and had it open up.
- 07-18-2011, 03:13 AM #7
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Possibly you are looking for JFileChooser which lets the user actually choose the file they want to open. Or possibly you want to merely create a File instance (no navigation needed).I would like to open the file so the user can see the results, without having to navigate to the file and manually open it
Either way, once you have the file use Desktop or JTextArea etc to taste. The basic difference between these is that in the first you let the OS (desktop etc) decide what "open" means and in the second your code implements whatever it is that you intend "open" to mean.Last edited by pbrockway2; 07-18-2011 at 03:16 AM.
- 07-18-2011, 03:21 AM #8
I give up!
- 07-18-2011, 03:32 AM #9
Similar Threads
-
Open File xls
By karno in forum NetBeansReplies: 4Last Post: 03-21-2010, 07:16 AM -
How to show or open a file download or file save dialog box
By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 04:21 AM -
Different Files Open in File -> Open Workspace
By mgm2010 in forum JCreatorReplies: 0Last Post: 04-11-2009, 02:14 PM -
Open File
By JavaLerner in forum SWT / JFaceReplies: 5Last Post: 07-12-2008, 06:41 PM -
To open an image file such as Jpeg file using JAva Program
By itmani2020 in forum Advanced JavaReplies: 10Last Post: 07-11-2008, 09:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks