选择图像表单系统..
JFileChooser chooser = new JFileChooser();
chooser.showOpenDialog(null);
File f = chooser.getSelectedFile();
String filename = f.getAbsolutePath();
String imageName=f.getName();
try {
ImageIcon ii;
ii = new ImageIcon( ImageIO.read(new File(f.getAbsolutePath())));
jLabel2.setIcon(ii);
} catch (Exception ex) {
ex.printStackTrace();
}
通过Web服务将数据上传到服务器
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("user_id", AuthConstants.id));
nvps.add(new BasicNameValuePair("profile_pic",imageName));
nvps.add(new BasicNameValuePair("profile_pic_path",filename));
try {
StringBuilder s = (StringBuilder) HttpWebService.postWebService(nvps, "services", "setting_update");
JOptionPane.showMessageDialog(null,"pic data :" );
System.out.println("File uploaded: " );
JOptionPane.showMessageDialog(null,"profile pic upload done (y)");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}