为什么我上传图片传到某个文件夹下不刷新的话图片不出来。程序读不出来这个图片,刷新下那个文件夹就好了,怎么解决啊,请高手帮帮忙

解决方案 »

  1.   

    private void initGUI() {
    try {
    this.setPreferredSize(new java.awt.Dimension(581, 410));
    {
    jPanel1 = new JPanel();
    this.add(jPanel1);
    jPanel1.setPreferredSize(new java.awt.Dimension(584, 407));
    jPanel1.setLayout(null);
    {
    jFileChooser1 = new JFileChooser();
    jPanel1.add(jFileChooser1);
    jFileChooser1.setMultiSelectionEnabled(false);
    int returnVal = jFileChooser1.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) { f = new File(jFileChooser1.getSelectedFile()
    .getAbsolutePath());
    if (f != null) {
    if (jFileChooser1.getSelectedFile()
    .getAbsolutePath().endsWith("jpg")) { FileInputStream ss = new FileInputStream(f);
    BufferedInputStream sss=new BufferedInputStream(ss);
    byte[] b = new byte[sss.available()];
    sss.read(b);
    sss.close();
    ss.close();
    int returnVa = jFileChooser1
    .showSaveDialog(this);
    if (returnVa == JFileChooser.APPROVE_OPTION) { String s = "src/picture/"
    + jFileChooser1.getSelectedFile()
    .getName();
    FileOutputStream o = new FileOutputStream(s);
    BufferedOutputStream oo=new BufferedOutputStream(o);
    oo.write(b);

    oo.close();
    o.close();
    String t=s;

    mai.getContentPane().removeAll();
    mai.dispose();
    new DishInFrame(main,t).show(true);

    }
    if (returnVa == jFileChooser1.CANCEL_OPTION) {
    mai.getContentPane().removeAll();
    mai.getContentPane().add(new DishPicturePanel(mai));
    mai.getContentPane().validate();
    } }else {
    JOptionPane.showMessageDialog(this, "图片必须是jpg格式的");
    mai.getContentPane().removeAll();
    mai.dispose();
    new DishInFrame(main).show(true);
    }


    }
    if (returnVal == jFileChooser1.CANCEL_OPTION) {
    mai.getContentPane().removeAll();
    mai.dispose();
    new DishInFrame(main).show(true); }
    jFileChooser1.setBounds(0, -6, 584, 413);
    }
    }
    } catch (Exception e) {
    e.printStackTrace();
    }
    }