大家都需要我的程序帮助。
每次运行时都会出现第一个窗口,但是当我按下浏览按钮时程序崩溃。
我也没有在NetBeans上收到任何错误。它只是说建立成功。
任何人都可以帮我解决这个问题吗?
谢谢。
代码:
public class MyJavaApplication {
public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException, IOException {
List<String> optionList1 = new ArrayList<String>();
optionList1.add("Cancel");
optionList1.add("Browse");
Object[] options1 = optionList1.toArray();
int value1 = JOptionPane.showOptionDialog(null,
"Please select the file you want to encrypt:",
"Open",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options1,
optionList1.get(0));
String option1 = optionList1.get(value1);
if (value1 == 1) {
JFrame frame = null;
JFileChooser fChoose = new JFileChooser(System.getProperty("user.home"));
int returnVal = fChoose.showOpenDialog(frame);
File myFile = fChoose.getSelectedFile();
FileInputStream fis = new FileInputStream(myFile);
BufferedReader stream = new BufferedReader(new InputStreamReader(fis, "ISO-8859-1"));
String line;
while ((line = stream.readLine()) != null) {
System.out.println("The text is\n" +line);
}
}
}
}