make an JFileChooser with chosen directory.
JFileChooser fc = new JFileChooser("directory");
and make it visible, then wait until one of the buttons is clicked.
showOpenDialog() : this method gives you an integer that indicates what button are clicked.
int val = fc.showOpenDialog(null);
if (val == fc.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream is = new ObjectInputStream(fileIn);
checkboxState = (boolean[]) is.readObject();
} catch (Exception e) {
e.printStackTrace();
}
}
the code above will read a selected file which has an serialized object if I press the open button.
JFileChooser fc = new JFileChooser("directory");
and make it visible, then wait until one of the buttons is clicked.
showOpenDialog() : this method gives you an integer that indicates what button are clicked.
int val = fc.showOpenDialog(null);
if (val == fc.APPROVE_OPTION) {
File file = fc.getSelectedFile();
try {
FileInputStream fileIn = new FileInputStream(file);
ObjectInputStream is = new ObjectInputStream(fileIn);
checkboxState = (boolean[]) is.readObject();
} catch (Exception e) {
e.printStackTrace();
}
}
the code above will read a selected file which has an serialized object if I press the open button.
댓글
댓글 쓰기