哪位专家能告诉我为什么符合条件的手机号码无法写入指定文件?该怎么改?


package com.aliyun.api.gateway.demo;

import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.http.HttpResponse;

import com.alibaba.fastjson.JSONObject;
import com.aliyun.api.gateway.demo.util.HttpUtil;
import com.aliyun.api.gateway.demo.util.HttpUtils;

public class Test {
    public static String cityname= "上海市";
    public static String query(String phone){
        String host = "https://api04.aliyun.venuscn.com";
        String path = "/mobile";
        String method = "GET";
        String appcode = "您自己的appcode";
        Map<String, String> headers = new HashMap<String, String>();
        //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);


        try {
            /**
            * 重要提示如下:
            * HttpUtils请从
            * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
            * 下载
            *
            * 相应的依赖请参照
            * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
            */
            HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
            String result = HttpUtil.readStreamAsStr(response.getEntity().getContent());
            JSONObject jsonObject = JSONObject.parseObject(result);
            JSONObject dataObject = jsonObject.getJSONObject("data");//从jsonObject对象中获取名为"data"的子属性的值,并将其转化为JSONObject对象
            return dataObject.getString("city");// 从dataObject对象中获取名为"city"的子属性的值,并将其作为返回结果返回
            //System.out.println(response.toString());
            //获取response的body
            //System.out.println(EntityUtils.toString(response.getEntity()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";//由于query方法的返回值类型为String,所以需要在try-catch语句块中使用return语句将data变量中的查询结果作为返回值返回
    }
    public static void main(String[] args) {
        FileWriter fileWriter = null;
        try {
            fileWriter = new FileWriter("D:\\手机号码.txt");
            String phone = "";
            for (int i = 0; i <= 9999; i++) {
                phone = String.format(Locale.ROOT, "135%04d0015", i);
                String city = query(phone);
                if (city.contains(cityname)) { // 修改了此行判断条件
                    fileWriter.write(phone + "\t");
                    fileWriter.flush();
                }
            }
            fileWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件写入失败,请检查文件路径和权限!");
        } finally {
            if (fileWriter != null) {
                try {
                    fileWriter.close();
                } catch (IOException ex) {
                }
            }
        }
    }
}

在main方法String city = query(phone);这一行之后把city变量打印出来看下api返回的城市到底是什么,可能返回的城市都不是[上海市]

String method = "GET";你确认GET可以?一般是POST,再不行你提供了appcode才好调试