日期:2014-05-17  浏览次数:20610 次

坐等高手!!!!输出到文本发生截断?何解?
public class pachong {
  public static void main(String[] args) throws Exception {  
  HttpClient httpClient = new DefaultHttpClient();//创建httpclient对象  
 
  //以下对url的”query=“后的内容更改,将所有可能的情况遍历一次,每次访问一次网站  
   
  String string="abddd";
   
   
   
  String uriString="http://dict.51daifu.net/search?query="+string;
  java.net.URI uri=new java.net.URI(uriString);
  HttpGet request=new HttpGet(uri);// HTTP请求
   
 System.out.println("executing request " + request.getURI()); //打印出请求的网站
 HttpResponse response = httpClient.execute(request); //用httpclient对象执行httpget对象也就是url 
HttpEntity entity = response.getEntity();//定义承载反馈的对象entity  
if(entity!=null){
BufferedReader reader = new BufferedReader(  
  new InputStreamReader(entity.getContent()));  
String str = null;  
   
Scanner scanner = new Scanner(reader);  
if (scanner != null) {
scanner.useDelimiter("\\Z");
str = scanner.next(); //遍历entity查找 才能完全输出反馈的源码  
str=new String (str.getBytes("GBK"),"utf-8");//编码转换 utf-8转换为gbk  
FileWriter outFileWriter=new FileWriter("D:\\first\\c.txt");//查询什么字生成该字的txt文件?
int x=str.length();
outFileWriter.write(str);
System.out.println(x);
System.out.println(str);
}
   
  else System.out.println("请输入正确的地址");}
  }
}


------解决方案--------------------
Java code

outFileWriter.flush();
outFileWriter.close();