在上传文件,选择文件的时候,往往会遇到路径选择的问题,比如,一般上传的默认路径是 我的文档,而我们恰好需要默认在桌面,那怎么办呢?
下面的内容也许会帮到你!
int result = 0;
File file = null;
String path = null;
JFileChooser fileChooser = new JFileChooser();
FileSystemView fsv = FileSystemView.getFileSystemView(); //注意了,这里重要的一句
System.out.println(fsv.getHomeDirectory()); //得到桌面路径
fileChooser.setCurrentDirectory(fsv.getHomeDirectory());
fileChooser.setDialogTitle("请选择要上传的文件...");
fileChooser.setApproveButtonText("确定");
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
result = fileChooser.showOpenDialog(chatFrame);
if (JFileChooser.APPROVE_OPTION == resul