netbeans编译环境编码是utf-8,服务器编码是GBK
代码如下:
try{
 path="ftp://user:pwd@ip/文件/资料/可惜.doc";
 String urlpath=new String(path.getByte("utf-8"),"gbk");
 URL url=new URL(path);
 URLConnection con=url.openConnection();
 DataInputStream dis=new DataInputStream(con.getInputStream);
 File file=new File(c:/);
 DataOutputStream dos=new DataOutputStream(new FileOutputStream(file));
 byte[]b=new byte[16];
 int lenth=0;
 while((lenth=dis.read(b)!=-1)){
    dos.write(b);
  }
 dos.flush();
}catch(Exception e){}大家给点帮助,谢谢!

解决方案 »

  1.   

    path中含有中文,URL url=new URL(urlpath);这样试试。
      

  2.   

    对,本来是URL url=new URL(urlpath);我打上去的时候打错了,所以还是那个问题
      

  3.   


    public static void main(String[] args)throws Exception{
        String path="ftp://user:pwd@ip/文件/资料/可惜.doc";
        String urlpath=new String(path.getBytes("utf-8"),"gbk");
        System.out.println(urlpath);//ftp://user:pwd@ip/鏂囦欢/璧勬枡/鍙儨.doc
    }
    //路径是乱码,找到文件才怪,转码不是这么转的
      

  4.   


    //试试下面这么,ftp没怎么做过,不熟悉
    public static void main(String[] args)throws Exception{
    String path="ftp://user:pwd@ip/文件/资料/可惜.doc";
        String urlpath=new String(URLEncoder.encode(path,"gbk"));
            System.out.println(urlpath);//ftp%3A%2F%2Fuser%3Apwd%40ip%2F%CE%C4%BC%FE%2F%D7%CA%C1%CF%2F%BF%C9%CF%A7.doc
    }
      

  5.   

    File file=new File(c:/);改为File file=new File("c:/可惜.doc");试试
      

  6.   

    我已经放弃了这种方法,我试着做了ut-8到GBK的转码,但只适用文件名全是中文的文件,最后我选择使用apache的组件,用FTPClient那里面设置一下就可以直接下载,真的很强大
      

  7.   

    ftp://[username]:[password]@[IP]/server1_new/file1.gz我的路径全部是英文为什么 也出现filenotfound 
      

  8.   


    用ftp查看器看下直接打开的路径是什么,然后跳转到你所需要的路径