Im creating an application that gets a list of .java and .class files from a chosen directory and places them in a JList. I am using Netbeans 7.1.2.
I have all the files being displaying in the JList like i want, what i cant seem to do is to open open the selected .java file in the jTextArea.
I need to get the file from the JList to pass it into the JTextArea but it is not working
try
{
FileReader reader= new FileReader( jlist.getSelectedValue() );
BufferedReader br = new BufferedReader( reader);
textarea.read( br );
br.close();
textarea.requestFocus();
}
catch(Exception e2) {}
Does anybody see where im going wrong?
You need to use the
read(...)method passing in a BufferedFileReader not thewrite(...)method if you are to read a file into a JTextArea. This should make sense to you since your goal here is to read, not to write.