JFileChooser.setSelectedFile("test.txt");

解决方案 »

  1.   

    sorry:
    JFileChooser.setSelectedFile(new File("test.txt"));
      

  2.   

    还是不行啊
    文本框中还是什么都没有啊
    下面是一段代码
    saveButton.addActionListener(new ActionListener(){
       public void actionPerformed(ActionEvent e){
    String msg;
    int result = fDialog.showSaveDialog(frame);
    if(result == JFileChooser.APPROVE_OPTION){

           //显示的文本方法如下:

    fDialog.setSelectedFile(new File("test.txt"));
          String fname = fDialog.getName(fDialog.getSelectedFile());
    File file = new File(fname);
    //fDialog.setSelectedFile(file);
    path = fDialog.getCurrentDirectory();
    //fDialog.setApproveButtonToolTipText("yes");
    fDialog.setDialogTitle("yes");
    String title = fDialog.getApproveButtonText();
                    //String title = fDialog.getDialogTitle();
                    //fDialog.setControlButtonsAreShown(false);
                    //System.out.println(title);
        //file = new File(fname);
          try{   
                 //file =new File(path+fname);
                 String absolutePath = path.getAbsolutePath();
                 int length = absolutePath.length();
                 int c = length - 1;
                 //String test = absolutePath.subString(1,3);
                if(absolutePath.substring(length - 1 ).equals("\\"))
                System.out.println(absolutePath + fname);
                else
                System.out.println(absolutePath + "\\" + fname);
                 FileOutputStream fout = new FileOutputStream(path+fname);
                 BufferedOutputStream bout= new BufferedOutputStream(fout);
                 DataOutputStream dout = new DataOutputStream(bout);
                 
                 //dout.writeInt(dataSize);
                 //for(int i = 0; i<dataSize; i++){
                  dout.writeChars("gen.nextDouble()");
                 //}
                 dout.flush();
                 fout.close();
                 System.out.println(dout.size() + "bytes written");
       
                  }
                  catch (IOException ee)
                  {
                   }