我可以正常下载的阿,你用URLConnection方法看看
下载程序:
public class aaa {
public static void main(String[] args) throws Exception{
String param = "test";
URL u = new URL("http://dict.cn/search/?q="+param);
URLConnection urlc = u.openConnection();
InputStream in = urlc.getInputStream();
FileOutputStream out = new FileOutputStream("f:/tmp.txt");
byte[] bf = new byte[512];
int b = 0;
while(true){
b = in.read(bf);
if(b<0) break;
out.write(bf,0,b);
}
out.close();
in.close();
}}
下载程序:
public class aaa {
public static void main(String[] args) throws Exception{
String param = "test";
URL u = new URL("http://dict.cn/search/?q="+param);
URLConnection urlc = u.openConnection();
InputStream in = urlc.getInputStream();
FileOutputStream out = new FileOutputStream("f:/tmp.txt");
byte[] bf = new byte[512];
int b = 0;
while(true){
b = in.read(bf);
if(b<0) break;
out.write(bf,0,b);
}
out.close();
in.close();
}}
解决方案 »
- 关于System.out.println问题
- 还是关于应用JAR的问题(基础强的人进,新手误拢)!
- 关于异常的菜问题,请教大家
- 用GIF图片表示后台忙时为什么总是显示得很慢????
- 关于表达式(请大家进来看看)
- java怎么样能获取windows目录?????????
- 请问jcreator里面的自动提示功能怎么只有jdk里面的类库方法提示,而没有j2ee里面的类库方法提示呢?
- 如何捕捉out of memory 的错误?
- 看了two weeks Thinking in java,看不大懂啊!
- java 如何将多维数组与多维数组 拼接起来
- 用URLConnection时发生奇怪问题
- 帮我看看怎么样引用没有打包的类
http://dict.cn/search/?q=测试
好像报错了
import java.io.*; class untitled1 {
public static void main(String[] args) throws IOException { URL url = new URL("http://sports.163.com/");
URLConnection conn = url.openConnection(); InputStream is = conn.getInputStream();
InputStreamReader sr = new InputStreamReader(is);
int BUFFER = 1024;
char[] cs = new char[BUFFER];
int code = 0;
StringBuffer sb = new StringBuffer();
while((code = sr.read(cs,0,BUFFER))!=-1){
sb.append(cs,0,code);
}
System.out.println(sb);
}
}
那个程序在java application中不会有乱码问题
如果改成bean在jsp中调用的话需要把中文编码为urf-8然后再发送过去
一个urf-8转码的方法
public String getStrByUTF8(String arg0){
if(arg0 == null)
return null;
byte[] str = arg0.getBytes();
StringBuffer sb = new StringBuffer();
for(int i=0;i<str.length;i++){
sb.append("%"+Integer.toHexString(str[i] & 0xFF));
}
return sb.toString();
}
http请求头里有多框架设置么 jdk1.4支持么
----------------------------------------------