public void open()
{
int returnVal = jfilechooser.showOpenDialog(jf); //jf is JFrame's reference
if(returnVal == JFileChooser.APPROVE_OPTION)
{
//to erase any text in the text area before adding new text
jtextarea.setText(null);
try
{
String fileName = jfilechooser.getSelectedFile().getPath();
String show=jfilechooser.getSelectedFile().getName();
Reader in = new FileReader(jfilechooser.getSelectedFile());
char[] buff = new char[100000];
int nch;
while((nch = in.read(buff, 0, buff.length)) != -1)
jtextarea.append(new String(buff, 0, nch));
String fileContent = jtextarea.getText();
jf.setTitle(show+" : S-Textpad");
}
catch(FileNotFoundException x)
{}
catch(IOException ioe)
{
System.err.println("I/O Error on Open");
}
}
}
答案 0 :(得分:2)
它看起来像:
但是我不知道代码是否编译并且至少有一条无用的行:
String fileContent = jtextarea.getText();