Reputation: 207
Good evening all, I was wondering what syntax I would use to get the size (mb) and the name of the selected file in my JFileChooser.
JFileChooser filedlg = new JFileChooser();
filedlg.showOpenDialog(null);
textField.setText(//File's name);
textField_1.setText(//File's size);
What would I use to replace the comments? All help is appreciated.
Upvotes: 1
Views: 3160
Reputation: 651
JFileChooser filedlg = new JFileChooser();
filedlg.showOpenDialog(null);
File selected = filedlg.getSelectedFile();
textField.setText(selected.getName());
textField_1.setText(selected.length());
String fullName = selected.getAbsolutePath();
Also, the .length() gives size in bytes, so you will have to transform it to whatever you want after.
http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html http://docs.oracle.com/javase/6/docs/api/java/io/File.html
Upvotes: 4