How to open a stored text file using java?

Respected Sir / Madam

I have a JList containing absolute path of files stored in my operating system in String format....I have added a ListSelectionListener...Now when i select an absolute path in the JList, the file should open ....I don't know how to do that....Hope you got my problem....Can any one pls help me out?

Thank you[

[351 byte] By [pradeep.p12a] at [2007-11-26 23:59:50]
# 1
what does "open" a file mean? think about it before you reply.....
georgemca at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 2
I mean, if i have any word document(for example) stored in windows xp os and if i wanna OPEN it, i usually double click that document......I want to OPEN it in the obove way using java Thank you
pradeep.p12a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 3
So you have a file name, and you want to cause that file to be opened with some other application. Why did you think that was a question about collections?
DrClapa at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 4

Yes....i want to open a file(word document) like the one we open by double clicking on it....Actually i have a JList which contains the path of files stored on my pc..So when i select any row, event occurs...Inside the public void valueChanged(ListSelectionEvent e) method i want have some instructions which will help me open the file......

Thank you...

pradeep.p12a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 5
I don't think he did think it was a question about collections.Neither do I.
ejpa at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 6

thats ok buddy! best of luck

U need to import

import javax.swing.*;

import javax.swing.event.*;

import java.awt.*;

import java.awt.event.*;

public void valueChanged(ListSelectionEvent e)

{

if (!e.getValueIsAdjusting()) {

String fileName=

optionList.getSelectedValue().toString();

final JFrame dialog = new JFrame(fileName);

JEditorPane viewer = new JEditorPane();

viewer.setEditable(false);

JScrollPane jsp = new JScrollPane(viewer);

try {

viewer.setPage("file:/" + fileName);

} catch (Exception e) {

viewer.setText("Error opening " + fileName + ": " + e);

}

dialog.getContentPane().add(jsp, BorderLayout.CENTER);

JButton closeButton = new JButton("Close");

closeButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

dialog.setVisible(false);

dialog.dispose();

}

});

dialog.getContentPane().add(closeButton, BorderLayout.SOUTH);

dialog.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

//dialog.pack();

dialog.setSize(600, 600);

dialog.show();

}

}

cvasu4a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 7
more irrelevant nonsense from the same source. Can you put a cork in it please?
ejpa at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 8
Thank you so much....But i dont want the contents of the file to b displayed in editor pane....I want the file itself to open.....Can any one pls help me out?
pradeep.p12a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 9
have a look here: http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javase6/desktop_api/
ThePeacha at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 10
Great....Thank you so much...Desktop Api works.....Thanking each and everyone who posted a reply here...
pradeep.p12a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 11
you should use the code that runs the proper software by Runtime classes' methods with the parameter of the file name.
subhaja at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...
# 12
Thank you so much..Ur solution is even better than the desktop api....I can do this in JDK 1.5 itself.....
pradeep.p12a at 2007-7-11 15:49:12 > top of Java-index,Core,Core APIs...