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){}大家给点帮助,谢谢!
代码如下:
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){}大家给点帮助,谢谢!
解决方案 »
- 谁有javatalk.jar的下载地址
- 一个简单的JAVASCRIPT,帮忙!!!!!!!!!!!!!!!!!!
- 数组遍历后插值问题
- 各位大侠:在Dos命令行中能够运行applet吗?
- 老问题:连接sybase数据库异常,送100分!
- 怎么提高sql语句查询的能力.
- 剩900,再散
- 菜鸟的一个问题:Exception in thread "main" java.lang.NoClassDefFoundError:HelloDate/java
- 各位大侠,小弟我装了j2sdk1.4.0-rc,可是不知是怎么用!不好意思请赐教!
- 报错:NumberFormatException: For input string
- 用JFrame画图的问题
- java问题,求解啊!小问题哦!
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
}
//路径是乱码,找到文件才怪,转码不是这么转的
//试试下面这么,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
}
用ftp查看器看下直接打开的路径是什么,然后跳转到你所需要的路径