JFileChooser.getSelectedFile().toString();

解决方案 »

  1.   

    返回绝对路径用
    String path = JFileChooser.getSelectedFile().getAbsolutePath();
    String path = JFileChooser.getSelectedFile().getCanonicalPath();//建议使用
      

  2.   

    String filename=txt1.getText()
    String str=""
    JFileChooser filechooser=new JFileChooser()
    Object obj=filechooser.getCurrentDirectory()
    str=obj.toString()
    String downfilename=str+"\\"+filename
      

  3.   

    String str=c:\temp\java
    我想是不是可以将"\"替换成"/",这样应该可以的.试试看.
      

  4.   

    System.getProperty("file.separator");
    check the file.separator then use!
      

  5.   

    用StringTokenizer将\转换成为\\
      

  6.   

    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.filechooser.*;
    import java.io.*;
    import java.util.*;public class PathTest extends JFrame
    implements ActionListener
    {
    public PathTest(){
    setSize(300,300);
    JPanel jp = new JPanel();
    JButton jb = new JButton("Click");
    jp.add(jb);
    jb.addActionListener(this);
    getContentPane().add(jp);
    }
    public void actionPerformed(ActionEvent e){
    JFileChooser jfc = new JFileChooser();
    int i = jfc.showSaveDialog(this);
    if(i==JFileChooser.APPROVE_OPTION)
    try{
    String path = jfc.getSelectedFile().getCanonicalPath();
    String perpath = makePathUnderWindows(path);
    System.out.println(path);
    System.out.println(perpath);
    File file = new File(perpath);
    file.createNewFile();
    }
    catch(Exception evt){}
    }
    public static void main(String[] args){
    new PathTest().show();
    }
    //转化路径
    public String makePathUnderWindows(String path){
    StringTokenizer sk = new StringTokenizer(path,"\\");
    StringBuffer sb = new StringBuffer("");
    if(sk.hasMoreTokens())sb.append(sk.nextToken());
    while(sk.hasMoreTokens()){
    sb.append("\\\\");
    sb.append(sk.nextToken());
    }
    return sb.toString();
    }
    }