大家晚上好,我想知道我将使用什么语法来获取 JFileChooser 中所选文件的大小 (mb) 和名称。
JFileChooser filedlg = new JFileChooser();
filedlg.showOpenDialog(null);
textField.setText(//File's name);
textField_1.setText(//File's size);
我用什么来替换评论?感谢所有帮助。
最佳答案
JFileChooser filedlg = new JFileChooser();
filedlg.showOpenDialog(null);
File selected = filedlg.getSelectedFile();
textField.setText(selected.getName());
textField_1.setText(selected.length());
String fullName = selected.getAbsolutePath();
此外,.length() 给出了以字节为单位的大小,因此您必须将其转换为您想要的任何内容。
http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html http://docs.oracle.com/javase/6/docs/api/java/io/File.html
关于java - 获取 JFileChooser 中所选文件的大小和名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23576111/